Open kevinrenskers opened 3 years ago
That's a very good point. I think the major problem I have right now is naming.
I already have a package called syntax-highlight
that can turn a syntax tree into html.
I think I should be able to rename that into syntax-tree-highlight
and move the grammar logic to a new package called syntax-tree
and then use that here
I started playing around by just cloning this repo and removing everything that has to do with Publish. There is still quite a lot of code left it seems, a lot of glue around a lot of different packages. One thing that I don't really understand is what the Inflector
is for? And the estimate
function in Grammar+syntaxTreeFactory.swift
. Can you please explain the architecture a little bit?
Btw, I'd be interested in integrating a standalone highlighter into https://github.com/loopwerk/Saga, my static site generator written in Swift. Currently it relies on Python dependencies to do the Markdown parsing and syntax highlighting, but I'd love to use pure Swift packages. There are some potential libraries for the Markdown parsing, but the highlighting is a bigger problem. Splash is interesting but only supports Swift grammar - maybe Splash could be extended with Textmate language support? 🤔
The estimate
is a function that given a a specific kind
in the syntax tree, tries to estimate what it should be marked as in the highlighted html. Kind is basically just a string so it has to make guesses as to what that kind means.
The Inflector is there to turn English plurals into singulars, because I saw a language using plurals once. So this way we catch them all in the same funnel.
So for example kotlin.statement.comment
or kotlin.statements.comments
will result be marked as <span class="comment">...</span>
The estimate function isn't the only way, it's just supposed to be a nice (works most of the time) default.
Before making this I tried getting Splash working for TextMate Languages and couldn't figure it out. If you get it working, I'd love to see it!
As for the architecture, I'm not sure if this answers your question, but the building blocks are:
estimate
function to have a nice default
This seems like a very cool library, the ability to use all these different kinds of grammars, especially from TextMate, is great. However, it's very much tied to Publish. Have you thought of making a version of this library that works independently from Publish, instead offering a function that takes in a HTML string and returns a highlighted HTML string?
syntax-highlight-publish-plugin
could then depend on that plugin I imagine?