Comments (4)
Since Type
only covers a part of the node types in an extended parser, and the library provides separate vocabulary for defining node types, I intentionally kept that enum out of the public interface. You can construct something like it, for a specific parser, by iterating through parser.nodeSet.types
and building up an object. Or, if you want to refer to node types statically, use their names. Does that help?
BlockResult should be exported:
It's boolean | null
, which is only a few characters more than the name. What is gained by exporting this?
My solution was to just construct an InlineContext for a given line
There's a bunch of other internal stuff that would probably have to be exposed for this (such as resolveMarkers
) and I'm not sure I want to complicate the public interface for this rather specific use. What kind of block are you defining here, and where do the problems with relative/absolute indices come from?
from markdown.
You can construct something like it, for a specific parser, by iterating through parser.nodeSet.types and building up an object.
I can just do this if you want to keep Type
private. I already do this to extract the numeric type ids for my Markdown extension.
It's boolean | null, which is only a few characters more than the name. What is gained by exporting this?
IMO it's just a bit of a surprising type, since I would normally expect this to be an enum with names for each case. The type name conveys that it's very specific to the block parsing context. Not a huge deal though.
There's a bunch of other internal stuff that would probably have to be exposed for this (such as resolveMarkers)
In my use case at least, I was able to stick to the current public interface with the exception of the constructor.
What kind of block are you defining here, and where do the problems with relative/absolute indices come from?
For example, I have a composite block that has a "header" on the first line followed by indented blocks. Such as:
@div[class: "foo"]:
**content!**
Then I have code like this that needs to parse through the header line, which involves many lookups to line.text
. I try to only use absolute positions everywhere to be consistent and avoid confusion. However the Line
structure does not expose methods to lookup substrings or characters based on absolute positions (exactly the issue in #6).
An alternative here would be a method like Line.toInlineContext(cx: BlockContext): InlineContext
that abstracts the details of the constructor.
from markdown.
The code you linked seems to have already moved in the meantime.
In any case, I can see the use for an abstraction to help here, but simply exporting the InlineContext
constructor feels dodgy—that does a bunch of things that don't make sense for a task like this. Maybe we should split off a superclass of InlineContext
that just does the position-offsetting and element-building, and export that instead? Not too sure about the name, though. Maybe InputWindow
or something.
from markdown.
I actually would also like to see the Type
enum exported. When dealing with the syntax tree, I find that I frequently am checking if a certain node is a certain type. Although yes I can clearly do node.type.name === 'StrongEmphasis'
, I think it would be much nicer from a dev perspective to be able to do node.type.name === MarkdownType.StrongEmphasis
.
In general, I find enums much better to use in this case, as they are a better guarantee of forwards compatibility and they improve discoverability. Although of course I can just make my own version of the enum, this enum would become outdated if a new node type was ever added to lezer-parser/markdown
. Although this is highly unlikely in this particular case (as the Markdown spec is fairly stable at this point), recreating an enum from a library is quite code-smelly. I'm also not sure I understand the reticence – what is lost by making this an export from the lib? Sure, the enum is not "complete" in an extended parser, but I can make it complete with:
import { Type as LezerMarkdownType } from '@lezer/markdown'
type ExtendedMarkdownType = MyCustomMarkdownNodeType | LezerMarkdownType;
from markdown.
Related Issues (20)
- Table extension does not follow GFM spec (cannot interrupt a paragraph) HOT 5
- Some reference documentation is not updated HOT 1
- The `line`-parameter in `BlockParser` `parse()`-methods should not be a side-effect HOT 2
- Unable to run "prepare" script HOT 3
- More extensions: Insert and Mark HOT 3
- Table parser does not create a TableCell element that is empty or only comprised of spaces/tabs. HOT 8
- Is removing language features possible? HOT 1
- Checklists/todos are highlighted as such without a trailing slash HOT 5
- heads up: swc fails to minify the package correctly HOT 3
- Code block breaks when backticks are inside a property HOT 1
- Autolink fails for URLs with >3 parts in the domain HOT 2
- Table folding not work HOT 1
- Autolinks and regular link URLs are both parsed as "URL" nodes
- Spec deviation with angle-bracketed link destination followed by title
- Add alerts to GFM HOT 1
- MDX support HOT 1
- Autolink ending with '/' in an image HOT 1
- Custom tags for table elements HOT 5
- Styling Codeblocks (Fenced Code) HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from markdown.