Closed retorquere closed 8 months ago
The ligatures it understands are here
Ah wait -- I had c
defined as a macro, and that interferes with expandUnicodeLigatures
This should give me a decent start. Parsing is bound to be better (certainly cleaner) with unified -- next up is sentence-casing and markup.
Oh yeah the ancestry would be handy -- that would be handled by standard unist handlers? Or is there something specific in unified-latex for this?
You should use unified-latex-util-visit
. It will give you fancy visitors.
How can I tell whether a node is in the first or another argument of the href
macro?
You need to look at the parent and do indexOf(self)
in the argument list.
Where does self
come from? Is that one of the arguments for the visit
handler?
I made up the word self
. You can look up the index of the current node via the info
object passed in from visit
the index is present in the info object but it is always undefined
.
where does the code live that packs the token stream into arguments based on the macros
parameter?
Look for the gobbleSingleArgument
function.
In visit
, can I add something to context
for child nodes, like inMathMode
?
In visit
, can I replace child nodes? Could I do something like this:
visit(tree, (node, info) => {
if (node.type === 'macro' && node.content.match(/^(url|href)$/)) {
node.args[0].content = [ { type: 'string', content: printRaw(node.args[0].content) } ]
}
})
and not mess up the AST? position
info would be lost for example.
It looks like visit
starts at the leaves and works up to the root -- is there a way to walk the tree starting at the root and working down?
edit: I suppose that answers my previous question about modifying child nodes in the parent.
You can pass in enter
and leave
functions to visit
to control the traversal method. You can mutate during visit, but if you just want to change a specific node, I recommend replaceNode
.
So in this case I would test each node's parent, see if it is a url
or href
and it is the first argument, and then replace itself.
In the end I will want to achieve something like this -- is there a way to do this replaceNode
ing and visit
ing inside the unified chain?
wrt context -- I need to apply sentencecasing during conversion, which is steered on information I can build top-down. I need this information available on the individual nodes as I'm transforming them. Is the context
something I can use for this, or should I just attach it to each node?
I'm not in this to cause us both frustration. Let's just call this exploration closed.
I'd like to take a stab at a bib(la)tex plugin. I have an existing parser which works well, but I wouldn't half mind sharing the work of upkeep 😄 . Where can I find information to get me started? Is this a sensible thing to do with unified-latex?