2 Replies Latest reply on Feb 25, 2016 10:03 AM by KuddRoww

    export paragraph as html

    KuddRoww Level 1

      I have a bunch of text that includes certain character sets that correspond to HTML entities - example the degrees symbol. Is it possible to export the contents of a paragraph as HTML so that HTML entities are handled by the conversion by a native ES function? And if not I'm hoping someone has done the legwork on this. My thoughts are that the export to HTML handles this task so it must be buried in the DOM somewhere. I've seen there's a function where I can export the paragraph to an HTML document, and I could then grab the contents of the text file and parse out file header footers - but it just feels better to have a function handle it.

       

      Conceptually this is what I'm hoping for:

       

      // Input - Dalton’s Law of Partial Pressures
      var p = app.selection[0];
      var pHTML = p.convertToHTML(); // Output Dalton’s Law of Partial Pressures
      
        • 1. Re: export paragraph as html
          [Jongware] Most Valuable Participant

          JavaScript's file export mapping can be set to UTF8, which is also perfectly valid for HTML. ... Are you trying to solve another problem?

           

          But that said, it's as easy as using a custom Replace function. Typing on my iPad so entirely from memory, but the general idea would be

           

          pHTML = p.replace (/[\u007F-\uFFFF]/g, function ( r ) { return '&#'+r.charCodeAt(0)+';'; } );

          • 2. Re: export paragraph as html
            KuddRoww Level 1

            I'm converting the documents into NLM format (which also supports UTF-8). The vendor sent a sample file for how they want the NLM structured and they did HTML entity conversions. So basically I'm being safer rather than sorry. This was exactly what I was looking for! I didn't realize that in HTML your entities can be in both hex and decimal - so you saved me from having to do a mapping! Thank-you, thank-you, thank-you.