greghendershott / frog

Frog is a static blog generator implemented in Racket, targeting Bootstrap and able to use Pygments.
916 stars 96 forks source link

Syntax highlighting for fenced code in lists #217

Closed sswatson closed 6 years ago

sswatson commented 6 years ago

Fenced code which is indented so as to be associated with a list item does not seem to get syntax highlighting.

1. My first list item. 

    ```python
    sum(range(100))
  1. My second list item.
greghendershott commented 6 years ago

Well that's weird. I'm surprised no one (including me) has ever noticed this. I'll try to fix this soon.

greghendershott commented 6 years ago

The markdown library parser is handling these correctly, and producing x-expressions like (pre ((class "brush: python")) (code () "sum(range(100))"))).

The problem is Frog's syntax-highlight function. It is looking for these only as top-level x-expressions (i.e. what will become direct children of the <body> element).

Instead it needs to walk the whole x-expression tree to look for these, and hand off to pygments.

In theory this is a quick fix. But I like to slow down and try to think of what else I might be forgetting, add regression tests, etc. So it may take me a day or two to push a commit and bump Frog on the package server.

ZelphirKaltstahl commented 6 years ago

I think I once had the same problem and thought it was just me being stupid not realizing this earlier. At that time I read about "* functions" in "The Little Schemer" and it came to me that I needed to use such a thing.

Two links to the code I use:

You probably already solved it, but maybe it'll somehow still be helpful. @greghendershott Btw.: Did you see https://github.com/greghendershott/markdown/issues/72 ? I still did not get around to really understand how parser combinators work, otherwise I might be able to add something there : /

greghendershott commented 6 years ago

@ZelphirKaltstahl Thanks. In terms of my existing code, I think it's a fairly straightforward change: commit 51730d0 -- (a) nest in a named let and (b) add a match clause to recursively walk child elements.

greghendershott commented 6 years ago

@ZelphirKaltstahl As for https://github.com/greghendershott/markdown/issues/72:

greghendershott commented 6 years ago

@sswatson OK I merged this to master and nudged the Racket package server to rescan; it has. You can update Frog to get this. Thank you for reporting this!