laurent22 / joplin-turndown

MIT License
8 stars 6 forks source link

Adding rule to prevent [[links]] from being escaped? #16

Open argenos opened 3 years ago

argenos commented 3 years ago

I'm wondering if it's possible to create a rule that prevents the brackets in [[links]] from being escaped?

Here is a sample text:

<p><strong>Magenta Annotations</strong></p>
<blockquote>When  put  to  the  test,  however,  it  invariably  produced  a  plastic  cup filled  with  a  liquid  that  was  almost,  but  nit  quite,  entirely  unlike  tea. (<a href="zotero://open-pdf/library/items/FE7B33LA?page=179">Adams 1979:179</a>)</blockquote>
<p><em>The origin of [[not entirely unlike X]] </em>(<a href="zotero://open-pdf/library/items/FE7B33LA?page=179">note on p.179</a>)</p>

I don't necessarily know in advance which tags will contain the [[links]] either. Any tips?

argenos commented 3 years ago

Using the commonmark rules as an example, I'm trying to do this:

Allow a rule to specify whether it wants its content escaped or not

Based on those examples, I tried the following with no success:

  converter.addRule('p', {
    filter: 'p',
    replacement: function (content) {
      return '\n\n' + content + '\n\n'
    }, 
    escapeContent: function() {
      return false;
    },
  })

  convert.emphasis = {
    filter: ['em', 'i'],

    replacement: function (content, node, options) {
     if (!content.trim()) return ''
     return options.emDelimiter + content + options.emDelimiter
    },
    escapeContent: function() {
      return false;
    },
  }

Just checking if this is possible with rules or if I might be missing something obvious. Thanks!

Edit: Caught one mistake from copy-pasting and the code above now works. The only remaining question is if there is a way to turn off escaping altogether in a setting, instead of having to redefine each rule and adding the escapeContent field.