[code] [textadept] Lexing markdown: folding sections, lexing fenced code blocks.

From: Nicholas Ochiel <nochiel.att.gmail.com>
Date: Sun, 3 Jun 2018 21:29:46 +0300

# 1. Lexing fenced code blocks

In markdown documents, I might have arbitrary languages in fenced blocks e.g.

``` haskell
-- code here

``` tex
\equation{ ... }

I would like the markdown lexer to embed the appropriate lexers.

html.lua seems to initialise every lexer that might be embedded in a
html document. As I receive and generate documents with a wide and
varied set of languages, doing the same thing for markdown seems a bit
excessive and possibly inefficient (In vim, I'd have to load the
relevant parsing even if the current document doesn't embed any code).
Might it be possible to "dynamically" embed the lexers depending on
the label on the fence?

Naively (I don't know what I'm doing), might it be possible to have
the code look something like this:


local fence_end_rule = #(lexer.newline * lexer.space^0 * P('```')^-1)
* P('```')
local fence_start_rule = #(P('```') * lexer.space^0 * P(function(input, index)
    _, _, fence_lang = input:find('^%s*(%w+)', index)
    ui.print ("fence_lang = " .. fence_lang)
    if fence_lang then
        local fence_lexer = lexer.load(fence_lang)
        lex:embed(fence_lexer, fence_start_rule, fence_end_rule)
        return index
end)) * P('```') * lexer.nonnewline^0 * lexer.newline^-1


#2. Folding '#' headers

- How might I fold markdown sections with '#'-style headers, with the
fold level determined by the number of hashes? Perhaps someone has
already written the relevant snippet?

Thanks for the work you've done on this excellent editor.
Nicholas Ochiel
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Sun 03 Jun 2018 - 14:29:46 EDT

This archive was generated by hypermail 2.2.0 : Mon 04 Jun 2018 - 06:35:06 EDT