markdowntosail function

Hi, 

I am trying to convert HTML I receive from a web service in to rich text. 

I have tried using the markdowntosail function found in Markdown to SAIL (v1.0.0) [com.appiancorp.ps.plugins.richtexttools] component and using it on 20.1

The purpose is to ensure I retain URL's that are held within the HTML.

Any other ideas/guidance would be greatly appreciated.

Thanks!

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    In the past I've written out-of-box Appian expression rules that parse certain simple HTML formatting to display in Rich Text on an Appian form (read-only of course).  It only supports bold, italic, underline, linebreaks, and hyperlinks.  If that sounds like enough for you, then I could dig up and attempt to post them here. Note it also does require the Regex Utilities plug-in.

  • Hi Mike, I am looking for the expression rule that you described in your post. Would you be willing to share your code with me or post it here? thank you.

  • 0
    Certified Lead Developer
    in reply to Michal Bönisch

    I thought I'd ended up posting this somewhere but after this long I have no  idea... so i'll attach it below:

    /* rule!GLBL_CMPT_RichTextHTMLPreview */
    a!localVariables(
      local!formatBreakdown: rule!GLBL_UTIL_GetParsedRichTextBreakdown(htmlText: ri!htmlText),
      
      a!richTextDisplayField(
        label: ri!label,
        labelPosition: rule!GLBL_replaceNull(ri!labelPosition, "COLLAPSED"),
        instructions: ri!instructions,
        showWhen: ri!showWhen,
        value: {
          a!forEach(
            local!formatBreakdown,
            a!richTextItem(
              text:  rule!GLBL_UTIL_FormatHTMLLinebreaksForTextDisplay(
                htmlText: fv!item.row
              ),
              style: {
                fv!item.formats
              },
              link: a!safeLink(
                uri: fv!item.link,
                showWhen: not(rule!GLBL_isBlank(fv!item.link))
              )
            )
          )
        }
      )
    )
    
    /* rule!GLBL_UTIL_GetParsedRichTextBreakdown */
    a!localVariables(
      local!formatChangeMarker: "[[[formatChange]]]",
    
      local!test: regexreplaceall(
        pattern: "(<[biu]>|<a href="".+?""|</[biua]>)",
        searchstring: ri!htmltext,
        replacementString: local!formatChangeMarker & "$1"
      ),
      local!array: split(local!test, local!formatChangeMarker),
    
      local!formatMarks: a!forEach(
        local!array,
    
        tostring(
          if(
            left(fv!item, 8) = "<a href=",
            "a{{" & extract(fv!item, "<a href=""", """>") & "}}",
            extract(
              left(fv!item, 4),
              "<",
              ">"
            )
          )
        )
      ),
    
      a!forEach(
        local!formatMarks,
        with(
          local!list: joinarray(index(local!formatMarks, enumerate(fv!index)+1), ";"),
          local!list1: regexreplaceall( "b(.+?)/b", local!list, "$1"),
          local!list2: regexreplaceall( "i(.+?)/i", local!list1, "$1"),
          local!list3: regexreplaceall( "u(.+?)/u", local!list2, "$1"),
          local!list4: regexreplaceall( "a\{\{.+?\}\}(.+?)/a", local!list3, "$1"),
          {
            row: regexreplaceall("<[bui]>|<a href="".+?"">|</[buia]>", local!array[fv!index], ""),
            formats: touniformstring(
              a!forEach(
                rule!GLBL_UTIL_removeBlankValuesFromArray( trim(split(local!list4, ";")) ),
                if(
                  fv!item = "i",
                  "EMPHASIS",
                  fv!item = "b",
                  "STRONG",
                  fv!item = "u",
                  "UNDERLINE",
                  left(fv!item,1) = "a",
                  {},
                  ""
                )
              )
            ),
            link: tostring(
              rule!GLBL_UTIL_removeBlankValuesFromArray(
                touniformstring(
                  a!forEach(
                    trim(split(local!list4, ";")),
                    extract(fv!item, "a{{", "}}")
                  )
                )
              )
            )
          }
        )
      )
    )
    
    
    /* rule!GLBL_UTIL_FormatHTMLLinebreaksForTextDisplay */
    a!localVariables(
      local!lineBrokenText: regexreplaceall(
        "<br */*>",
        substitute(
          substitute(ri!htmlText, char(13), ""),
          char(10), 
          ""
        ),
        char(10)
      ),
      
      local!lineBrokenText
    )

    Note that this is 3 separate expression rules; also they make use of a few helper expression rules (like "ReplaceNull" and "RemoveBlankArrayMembers") that you may need to implement yourself in your own system and swap in for the rules named in these.

Reply
  • 0
    Certified Lead Developer
    in reply to Michal Bönisch

    I thought I'd ended up posting this somewhere but after this long I have no  idea... so i'll attach it below:

    /* rule!GLBL_CMPT_RichTextHTMLPreview */
    a!localVariables(
      local!formatBreakdown: rule!GLBL_UTIL_GetParsedRichTextBreakdown(htmlText: ri!htmlText),
      
      a!richTextDisplayField(
        label: ri!label,
        labelPosition: rule!GLBL_replaceNull(ri!labelPosition, "COLLAPSED"),
        instructions: ri!instructions,
        showWhen: ri!showWhen,
        value: {
          a!forEach(
            local!formatBreakdown,
            a!richTextItem(
              text:  rule!GLBL_UTIL_FormatHTMLLinebreaksForTextDisplay(
                htmlText: fv!item.row
              ),
              style: {
                fv!item.formats
              },
              link: a!safeLink(
                uri: fv!item.link,
                showWhen: not(rule!GLBL_isBlank(fv!item.link))
              )
            )
          )
        }
      )
    )
    
    /* rule!GLBL_UTIL_GetParsedRichTextBreakdown */
    a!localVariables(
      local!formatChangeMarker: "[[[formatChange]]]",
    
      local!test: regexreplaceall(
        pattern: "(<[biu]>|<a href="".+?""|</[biua]>)",
        searchstring: ri!htmltext,
        replacementString: local!formatChangeMarker & "$1"
      ),
      local!array: split(local!test, local!formatChangeMarker),
    
      local!formatMarks: a!forEach(
        local!array,
    
        tostring(
          if(
            left(fv!item, 8) = "<a href=",
            "a{{" & extract(fv!item, "<a href=""", """>") & "}}",
            extract(
              left(fv!item, 4),
              "<",
              ">"
            )
          )
        )
      ),
    
      a!forEach(
        local!formatMarks,
        with(
          local!list: joinarray(index(local!formatMarks, enumerate(fv!index)+1), ";"),
          local!list1: regexreplaceall( "b(.+?)/b", local!list, "$1"),
          local!list2: regexreplaceall( "i(.+?)/i", local!list1, "$1"),
          local!list3: regexreplaceall( "u(.+?)/u", local!list2, "$1"),
          local!list4: regexreplaceall( "a\{\{.+?\}\}(.+?)/a", local!list3, "$1"),
          {
            row: regexreplaceall("<[bui]>|<a href="".+?"">|</[buia]>", local!array[fv!index], ""),
            formats: touniformstring(
              a!forEach(
                rule!GLBL_UTIL_removeBlankValuesFromArray( trim(split(local!list4, ";")) ),
                if(
                  fv!item = "i",
                  "EMPHASIS",
                  fv!item = "b",
                  "STRONG",
                  fv!item = "u",
                  "UNDERLINE",
                  left(fv!item,1) = "a",
                  {},
                  ""
                )
              )
            ),
            link: tostring(
              rule!GLBL_UTIL_removeBlankValuesFromArray(
                touniformstring(
                  a!forEach(
                    trim(split(local!list4, ";")),
                    extract(fv!item, "a{{", "}}")
                  )
                )
              )
            )
          }
        )
      )
    )
    
    
    /* rule!GLBL_UTIL_FormatHTMLLinebreaksForTextDisplay */
    a!localVariables(
      local!lineBrokenText: regexreplaceall(
        "<br */*>",
        substitute(
          substitute(ri!htmlText, char(13), ""),
          char(10), 
          ""
        ),
        char(10)
      ),
      
      local!lineBrokenText
    )

    Note that this is 3 separate expression rules; also they make use of a few helper expression rules (like "ReplaceNull" and "RemoveBlankArrayMembers") that you may need to implement yourself in your own system and swap in for the rules named in these.

Children
No Data