script generated at html export

godzillate's Avatar


11 Apr, 2016 08:52 AM

Greetings, I've been having an issue with the last Marked 2 (or last two?) versions. Every time I export to html there is a script at the end of it and I can't figure out what it does or how to stop it from being in the file.

The script looks like this:

<script>(function(factory){if(typeof define==="function"&&define.amd){define("bidi_helpers",[],factory)}else{window.bidi_helpers=factory()}})(function(){var module={};module.Dir={RTL:-1,UNKNOWN:0,LTR:1};module.Format={LRE:"‪",RLE:"‫",PDF:"‬",LRM:"‎",RLM:"‏"};module.ltrChars_="A-Za-zÀ-ÖØ-öø-ʸ̀-֐ࠀ-῿Ⰰ-﬜︀-﹯﻽-￿";module.rtlChars_="֑-߿יִ-﷿ﹰ-ﻼ";module.ltrDirCheckRe_=new RegExp("^[^"+module.rtlChars_+"]*["+module.ltrChars_+"]");module.ltrCharReg_=new RegExp("["+module.ltrChars_+"]");module.hasAnyLtr=function(text){return module.ltrCharReg_.test(text)};module.rtlDirCheckRe_=new RegExp("^[^"+module.ltrChars_+"]*["+module.rtlChars_+"]");module.rtlRe=module.rtlDirCheckRe_;module.isRtlText=function(text){return module.rtlDirCheckRe_.test(text)};module.isLtrText=function(text){return module.ltrDirCheckRe_.test(text)};module.isRequiredLtrRe_=/^http:\/\/.*/;module.hasNumeralsRe_=/\d/;module.estimateDirection=function(text,detectionThreshold){var rtlCount=0;var totalCount=0;var hasWeaklyLtr=false;var tokens=text.split(/\s+/);for(var i=0;i<tokens.length;i++){var token=tokens[i];if(module.isRtlText(token)){rtlCount++;totalCount++}else{if(module.isRequiredLtrRe_.test(token)){hasWeaklyLtr=true}else{if(module.hasAnyLtr(token)){totalCount++}else{if(module.hasNumeralsRe_.test(token)){hasWeaklyLtr=true}}}}}return totalCount==0?(hasWeaklyLtr?module.Dir.LTR:module.Dir.UNKNOWN):(rtlCount/totalCount>detectionThreshold?module.Dir.RTL:module.Dir.LTR)};return module});(function(factory){if(typeof define==="function"&&define.amd){define("bidiweb",["bidi_helpers"],factory)}else{window.bidiweb=factory(bidi_helpers)}})(function(bidi_helpers){var module={};var IProcessor={makeRtl:function(element){},makeLtr:function(element){}};var css_processor=function(classes){return{makeRtl:function(element){element.classList.add(classes.rtl)},makeLtr:function(element){element.classList.add(classes.ltr)}}};var style_processor=function(falign){return{makeRtl:function(element){"rtl";if(falign){"right"}},makeLtr:function(element){"ltr";if(falign){"left"}}}};module.processors={css:css_processor,style:style_processor};var nodeListMock=function(node){var list=[node];list.item=function(i){return list[i]};return list};module.process=function(query,processor){var elements;if(query instanceof NodeList){elements=query}else{if(query instanceof Node){elements=nodeListMock(query)}else{elements=document.querySelectorAll(query)}}module.process_elements(elements,processor);return elements};module.process_elements=function(elements,processor){for(var index=0;index<elements.length;index++){var element=elements.item(index);var text=element.textContent||element.value||element.placeholder||"";var dir=bidi_helpers.estimateDirection(text,0.4);if(dir==bidi_helpers.Dir.RTL){processor.makeRtl(element)}else{if(dir==bidi_helpers.Dir.LTR){processor.makeLtr(element)}}}};module.process_css=function(query,classes){var proc=module.processors.css(classes);return module.process(query,proc)};module.process_style=function(query,falign){var;return module.process(query,proc)};{return module.process_style(query,true)};module.css=function(query){return module.process_css(query,{rtl:"rtl",ltr:"ltr"})};module.htmlToElement=function(html){var container=document.createElement("div");container.innerHTML=html;return container};module.html_css=function(html){var container=module.htmlToElement(html);var nodes=container.querySelectorAll("*");module.css(nodes);return container.innerHTML};module.html_style=function(html){var container=module.htmlToElement(html);var nodes=container.querySelectorAll("*");;return container.innerHTML};return module});</script>

I attached a sample html file.

  1. Support Staff 1 Posted by Brett on 11 Apr, 2016 02:47 PM

    Brett's Avatar

    This is the javascript that determines whether a paragraph or headline
    is in Arabic or other RTL format. I currently have it embedded by
    default as it's an automatic feature of the preview (only included if
    the style is also embedded based on save dialog settings). Are you
    finding the output problematic?

  2. Support Staff 2 Posted by Brett on 11 Apr, 2016 02:50 PM

    Brett's Avatar

    I just realized I did add an option to disable this feature. Under
    Preferences->Style->Layout and Typography, you can disable "Detect and
    style RTL text" to remove the script.


  3. 3 Posted by godzillate on 11 Apr, 2016 08:53 PM

    godzillate's Avatar

    Weird, that option is not enabled on my install. I tried to enable it, exported to html, the script is there. Disabled the option, script is there, too.

    It's not problematic per se, but I export my articles to html for clients and I don't want any unnecessary code in there that might throw them off and give me complaints.

  4. Support Staff 4 Posted by Brett on 12 Apr, 2016 03:05 PM

    Brett's Avatar

    Ok, I'll take a look at why it's not excluding that script when the
    option is disabled. Can I ask why you share the HTML version and not a
    PDF with clients?


  5. 5 Posted by godzillate on 12 Apr, 2016 06:56 PM

    godzillate's Avatar

    Sure, I write my articles in Markdown and export to HTML because it's easy to just copy and paste the code into a CMS. In a perfect world I'd just give them the Markdown files and they would export to whatever they like. Sadly, we are not there yet.

  6. Support Staff 6 Posted by Brett on 12 Apr, 2016 07:03 PM

    Brett's Avatar

    If you export without the style embedded, you should get something much easier to embed in other platforms (sans styling, style sheets, and scripts).


  7. 7 Posted by godzillate on 14 Apr, 2016 10:43 AM

    godzillate's Avatar

    I know, the problem is that I have to use a style because I work with a marketing agency that uses it's own branding. All the exported documents have the same style.

  8. 8 Posted by Jeremy Douglass on 28 Dec, 2017 12:34 AM

    Jeremy Douglass's Avatar

    I believe that there is currently a bug in Marked 2 (2.5.10 930) with disabling this RTL detect feature.

    I have a preprocessor that injects "class='rtl'" html elements, and an attached custom css stylesheet that styles them with direction:rtl. On opening a document in Marked 2 with my preprocessor enabled and the "Preferences > Style > Detect and style RTL text" unchecked, strange things happen -- for example, nested rtl > ltr elements cannot override direction by any method (!important, etc.). Using inspect and attempting to style elements directly in the DOM likewise has no effect -- it appears to be overridden by Javascript, even though the preference is unchecked.

    When I turn on the detect checkbox on an open document, it produces no visual change -- nested ltr elements are still being forced rtl. When I then turn the checkbox off again, it seems to strips all 'rtl' class information from the document -- including all of my 'rtl' class tags that were originally injected by my preprocessor. Whether the option is on or off, my document is incorrect when compared to a web preview.

    I would love a setting where the Marked 2 RTL-detector can be just completely disabled -- or advice on a workaround. For a temporary workaround I have changed the name of my pre-processor class from 'rtl' to something else -- this seems to prevent Marked 2 from interfering with it -- but that isn't a good long-term solution.

  9. Support Staff 9 Posted by Brett on 28 Dec, 2017 08:58 PM

    Brett's Avatar

    This is because of a workaround I had to do at one point, as a result
    the only difference when exporting without RTL detection is that it
    doesn't actually style the RTL, but still applies the classes. Using a
    different name in your script is ideal, but I'd consider changing the
    class that Marked applies to something more namespaced (eg mk-rtl) to
    avoid conflicts. I'll also take a look at disabling the script on export


  10. 10 Posted by Jeremy Douglass on 29 Dec, 2017 07:12 PM

    Jeremy Douglass's Avatar

    Thank you su much, Brett -- namespacing "mk-rtl" would be a perfect fix.

    I'd love to be able to pass toolchains that use class='rtl' through Marked 2 unchanged.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Already uploaded files

  • 2016-04-11.html 25 KB

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac