Extension behaving like **strong**


#1

Hello!

First I would like to thank the developers of FoldingText for a really awesome application! Now on to my question.

I use FoldingText a lot for taking notes in scientific and mathematical subjects. I have therefore built up a great need to use latex for typesetting formulas in FoldingText. After a long period of frustration and looking at a lot of options I finally found a javascript package that is able to take a latex string and return a html version of the formula: Katex

I have verified that it works as expected within FoldingText, but my current set up is not very elegant. Right now my extension typesets any line with a @katex tag and leaves the original latex-string visible. This is of course not optimal.

What I would like to do is to mimic what FoldingText is doing for **, that is to replace any string within some delimiter characters with the typeset formula and show the latex code, as well as allow editing whenever the cursor enters the delimited region. Is this possible to do within an extension/plugin? I tried to look through the source for examples of how to do this but failed.

Any pointers to extensions that solve my original typesetting problem, extensions that have examples of what I want to do or pointers to examples in the source would be greatly appreciated!

// Jonatan


#2

It’s a bit complicated and intertwined with FoldingText internals… but as far as I remember this is how FoldingText hides **'s:

  1. All the HTML is always there, elements are NOT being added/removed as you move the cursor.

  2. Instead CSS rules are being used to show/hide the elements.

  3. Elements that are normally hidden (such as **) have a CSS rule to hide them.

  4. When the cursor is in text it adds “cm-currentsyntax” to all elements in that area.

  5. “cm-currentsyntax” has a later !important rule to show all elements… overriding the default hiding of those elements.

I “think” that’s the core of it. You can dig into the details a bit more by looking at the style rules inside the FoldingText.app package: FoldingText.app/Contents/Resources/dist/apps/base.less. In particular search down for the Syntax Hiding comment to see the details of how it works.

Jesse