Skip to content
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

Add reference field to LinkReference, ImageReference #23

Closed
wants to merge 3 commits into from

Conversation

rubys
Copy link

@rubys rubys commented Aug 8, 2018

No description provided.

readme.md Outdated
@@ -723,10 +723,16 @@ its `url` and `title` defined somewhere else in the document by a
`referenceType` is needed to detect if a reference was meant as a
reference (`[foo][]`) or just unescaped brackets (`[foo]`).

`reference` provides the original raw reference, if the `referenceType` is
`full` and the reference differs from the `identifier`. This enables
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to drop the case where referenceType is full? Although it’s not needed to create the original markdown for collapsed or shortcut references in remark, it’s one less condition in the spec?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it could be useful for linting, or non-HTML and non-markdown outputs?

Copy link
Author

@rubys rubys Aug 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two thoughts:

  1. I don't know how to trade-off the additional memory usage vs the overhead (conceptual and runtime) of a single if-check.

  2. What I do know is that 50+ tests within the remark repository alone will need to be updated should the check for full and different than identifier be dropped. If there is that much change within the repository, chances are high this change will affect somebody's test suite out there.

As to usefulness, this comment was not meant to be an exhaustive list. I did provide a patch for remark-stringify, so this new property is arguably useful in the generation of markdown (i.e., not just the consumption).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • For the trade-off, I think that’s fine. How many references are out there really.
  • For the test suite: the remarkjs repo has a script: script/regenerate-fixtures that updates the ASTs for all tests, and you can check the diff if it works or not. I personally don’t see the addition of a property to nodes as a breaking change. Even if someones tests break because of fixtures, I don’t think actual (not sure how to call it) code will break.
  • And usefulness: I meant that the addition of a reference to non-full references could potentially be useful for other things, like linting, even though we’re now discussing stringifying to markdown and html, which doesn’t need it.

@rubys
Copy link
Author

rubys commented Aug 8, 2018

If you are thinking about the linting case, shouldn't references also be captured for Footnote Reference, Definitions and FootnoteDefinition too?

@wooorm
Copy link
Member

wooorm commented Aug 8, 2018

@rubys Darn, that’s true. If we’re adding a value that is the “original” version of identifier (which makes sense to me), we should use a different name though... Any suggestions?

@wooorm
Copy link
Member

wooorm commented Aug 8, 2018

Some ideas, mostly bad ones, sorted from like to dislike:

  • identifierRaw
  • identifierSource
  • reference
  • location
  • originalIdentifier
  • id

@rubys
Copy link
Author

rubys commented Aug 8, 2018

I was going to suggest rawIndentifier which is essentially your first choice.

@wooorm
Copy link
Member

wooorm commented Aug 8, 2018

Hmm. OK.

But now I’m wondering. We could add raw versions of most properties, e.g., they are mostly decoded to remove entities for example, so if we’re going the route of adding raw versions of computed properties, would an optional raw object on nodes make more sense? That could store the original versions of props, but also opening and closing markers, white-space, or similar?

I see a value in this, even though it’s far away before it’s implemented.
But I fear it would conflict if we add this property outside of that object now?

@rubys
Copy link
Author

rubys commented Aug 8, 2018

We appear to be wandering off into Yak Shaving territory. :-)

I don't think we need to worry to much about a linter application requirements. An application could safely get the original source via file.contents.slice(node.position.start.offset, node.position.end.offset).

We don't have that luxury in mdast_util_to_hast as (1) it doesn't currently have access to file, and (2) as a utility, it doesn't know whether the original source is in markdown format (i.e., there could have been a transformation to MDAST other than remark_parse.

My leaning are to not boil the ocean, and just focus on the requirements we know. After all, in all other cases than full for link and image references, the raw identifier can be determined just by looking at other MDAST properties.

@wooorm
Copy link
Member

wooorm commented Aug 8, 2018

I know it’s yak shaving, but it’s also fair to think about it for a day!
However, what we require can be accomplished with a) .identifierRaw, and b) .raw.identifier.

a) is simple for now, but could stand in the way of .raw being added in the future!

@rubys
Copy link
Author

rubys commented Aug 14, 2018

@woorm: what's the verdict?

@wooorm
Copy link
Member

wooorm commented Aug 15, 2018

I think I prefer reference. Even in relation to identifier (on non-reference) nodes it’s okay I believe.
That way it won’t conflict with any “raw” properties in the future.

What do you think? Big mistake?

For the implementation, I’m partial to whether only references, or all nodes with an identifier should receive these new props. Whatever works for you!

…tifier.

This either takes the form of a `reference` or a `definition` property.
@rubys
Copy link
Author

rubys commented Aug 17, 2018

I believe I've addressed your feedback. Note: I went with definition for Defintion and FootnoteDefinition nodes.

If this looks correct overall, I'll update remarkjs/remark#346 to match. I don't believe that syntax-tree/mdast-util-to-hast#22 has to change.

readme.md Show resolved Hide resolved
readme.md Show resolved Hide resolved
readme.md Show resolved Hide resolved
@wooorm wooorm closed this in dbb1ede Aug 31, 2018
wooorm added a commit to remarkjs/remark that referenced this pull request Oct 14, 2018
* remark-parse: add label to definition, footnote definition, link reference, image reference,
  footnote reference
* remark-stringify: use full reference if no type is set

Related to syntax-tree/mdast#23.
Related to syntax-tree/mdast-util-to-hast#22.

Supersedes GH-346.

Closes GH-363.

Reviewed-by: Christian Murphy <christian.murphy.42@gmail.com>

Co-authored-by: Sam Ruby <rubys@intertwingly.net>
wooorm added a commit to syntax-tree/mdast-util-to-hast that referenced this pull request Nov 11, 2018
Closes GH-22.
Related to GH-20.
Related to syntax-tree/mdast#23.
Related to remarkjs/remark#346.

Co-authored-by: Sam Ruby <rubys@intertwingly.net>
wooorm added a commit to syntax-tree/mdast-util-to-hast that referenced this pull request Nov 11, 2018
Closes GH-22.
Related to GH-20.
Related to syntax-tree/mdast#23.
Related to remarkjs/remark#346.

Co-authored-by: Sam Ruby <rubys@intertwingly.net>
@wooorm wooorm changed the title Add reference property to LinkReference and ImageReference interfaces. Add reference field to LinkReference, ImageReference Aug 12, 2019
@wooorm wooorm added ⛵️ status/released 🗄 area/interface This affects the public interface 🦋 type/enhancement This is great to have labels Aug 12, 2019
@wooorm wooorm added the 💪 phase/solved Post is done label Apr 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🗄 area/interface This affects the public interface 💪 phase/solved Post is done 🦋 type/enhancement This is great to have
Development

Successfully merging this pull request may close these issues.

3 participants