-
Notifications
You must be signed in to change notification settings - Fork 137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AST metadata -> always quadruples, %{comment: true} #337
Comments
It feels like ExDoc should roll its own AST to HTML, which should be straight-forward, and we can prune any node that we add. Especially because it is likely that we will make the AST more tailored to ExDoc as more time passes. |
due to other requirements, in ExDoc we already have our own way of transforming ast->html. This is mostly about markdown->ast, we need to get the extra information out of Earmark and put it into ast somehow. |
Ah, I see! |
I would advice against adding pseudo attributes to the AST as we have annotations for this https://github.com/pragdave/earmark#earmarktransformtransform2 so when parsing with the
It might even be a good idea to default the
|
fantastic! My only suggestion would be to consider not returning different AST shape based on whether an option is set or not; instead always return the same shape (4-tuple), just with empty annotations.
as in, Line NumBer? :) nitpick: unless you need to maintain backwards compat, I'd consider switching this to
but at the same time it doesn't matter how the key is called, I'm really happy there's already infrastructure for this! In any case, I'm happy to look into returning :lnb in the ast. |
ad Namingoh I was just lazy please pick a name you would like, as long as it reads BTW Earmark also uses ad 4 tuplesAdding always an empty map, why not, however @josevalim had made a point concerning this when we talked about comments, that not having the same shape might also be an advantage sometimes. Adding an empty map might induce a different kind of pattern matching than matching on the shape. |
@RobertDober if 3 vs 4 element tuple is useful to differentiate between comment and non-comment nodes, I believe the best way to go is to standardise on 4 element tuples and put |
Ok with me to have always 4 element tuples, for comments I am not sure but it is not important, whatever serves ex_doc best... That all said I must emphasise that right now I can only spend minimal time on Earmark as I have found a job again and I have no idea of the ETA of 1.5. Sorry about that (who would not be sorry to work with legacy Rails code instead of Elixir, right?) |
Out of curiosity, what other keys beyond :meta do you expect to have?
…> On 27 May 2020, at 12:45, Robert Dober ***@***.***> wrote:
Ok so finally I'll take this on, I prefer to not have %{comment: true} but %{meta: %{comment: true}} because that is the only key reserved, everything else can be used by client code. Now if this is too clumsy I can change the contract on the AST, but it is quite ugly, I believe to reserve :comment and :meta
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
I apologize, you were to fast for me... Sorry for having wasted your time. |
Sounds good to me! |
Pushing into 1.4.6 as #342 needs a hotfix |
Finally got time to work on this @josevalim @wojtekmach is it ok for you to maintain that the comment node starts with the symbol I did not overlook that we had discussed this already, or did I? I can change that quickly before release so no stress with that, I guess you will be quite busy right now :) |
1 similar comment
Finally got time to work on this @josevalim @wojtekmach is it ok for you to maintain that the comment node starts with the symbol I did not overlook that we had discussed this already, or did I? I can change that quickly before release so no stress with that, I guess you will be quite busy right now :) |
I don’t have an opinion and either sounds good to me, I will be most likely pattern matching on just |
so I'll keep the symbol |
First some background, in ExDoc currently for this module:
when generating docs, we are emitting the following warning which is useful to find and fix broken references:
I'd like to make the warning more precise and mention file:line like this:
To do that, I need to know where the warning happened within the markdown document.
Today, when parsing markdown into AST we get:
and I believe the best option to generate the warning above is to put the line on the ast node (perhaps with
:lines
option or something)We already use line for Earmark errors, so it doesn't seem like a huge leap to add it to nodes.
The problem is of course when we transform ast back into HTML, we probably don't want to keep the line attribute around so I thought maybe prefixing it with
_
will signal it should be ignored. And even though the line number is an integer, to be consistent with the rest of AST, it probably makes sense to write it down as a string like above.Another option, which is much bigger change, is to represent the AST as a 4-element tuple,
{tag, metadata, attributes, ast}
:and here we have a clear distinction between the node contents and metadata.
Besides which line, I think another useful piece of information would be which column the given node starts at. But imho this is definitely lower priority.
What do you think? Perhaps there's an easier way to support my ExDoc use case?
cc @RobertDober @josevalim
The text was updated successfully, but these errors were encountered: