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

Position of final ; in character reference not included in text that is ended by character reference #38

Closed
4 tasks done
599316527 opened this issue May 27, 2024 · 3 comments
Labels
💪 phase/solved Post is done

Comments

@599316527
Copy link

Initial checklist

Affected packages and versions

mdast-util-from-markdown@2.0.0

Link to runnable example

https://codesandbox.io/p/sandbox/ecstatic-kare-jrjg63?layout=%257B%2522sidebarPanel%2522%253A%2522EXPLORER%2522%252C%2522rootPanelGroup%2522%253A%257B%2522direction%2522%253A%2522horizontal%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522id%2522%253A%2522ROOT_LAYOUT%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522clwkj36qd00063b6i1xez9e5d%2522%252C%2522sizes%2522%253A%255B100%252C0%255D%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522EDITOR%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522id%2522%253A%2522clwkj36qc00023b6i9zm256ih%2522%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522SHELLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522id%2522%253A%2522clwkj36qd00033b6incw8582z%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522DEVTOOLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522id%2522%253A%2522clwkj36qd00053b6igcv486qo%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%252C%2522sizes%2522%253A%255B50%252C50%255D%257D%252C%2522tabbedPanels%2522%253A%257B%2522clwkj36qc00023b6i9zm256ih%2522%253A%257B%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522clwkj36qc00013b6ismt4hxpe%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522FILE%2522%252C%2522filepath%2522%253A%2522%252Fsrc%252Findex.html%2522%252C%2522state%2522%253A%2522IDLE%2522%257D%255D%252C%2522id%2522%253A%2522clwkj36qc00023b6i9zm256ih%2522%252C%2522activeTabId%2522%253A%2522clwkj36qc00013b6ismt4hxpe%2522%257D%252C%2522clwkj36qd00053b6igcv486qo%2522%253A%257B%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522clwkj36qd00043b6isgfgfwh2%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522UNASSIGNED_PORT%2522%252C%2522port%2522%253A0%252C%2522path%2522%253A%2522%252F%2522%257D%255D%252C%2522id%2522%253A%2522clwkj36qd00053b6igcv486qo%2522%252C%2522activeTabId%2522%253A%2522clwkj36qd00043b6isgfgfwh2%2522%257D%252C%2522clwkj36qd00033b6incw8582z%2522%253A%257B%2522tabs%2522%253A%255B%255D%252C%2522id%2522%253A%2522clwkj36qd00033b6incw8582z%2522%257D%257D%252C%2522showDevtools%2522%253Atrue%252C%2522showShells%2522%253Afalse%252C%2522showSidebar%2522%253Atrue%252C%2522sidebarPanelSize%2522%253A15%257D

Steps to reproduce

import { fromMarkdown } from "mdast-util-from-markdown";

// const doc = fs.readFileSync("example.md", "utf8");

const doc = `abc _*_ efg`;
const tree = fromMarkdown(doc);

const emphasisEl = tree.children[0].children[1];
const starTextEl = emphasisEl.children[0];

console.log(emphasisEl.position);
// -> {
//   start: { line: 1, column: 5, offset: 4 },
//   end: { line: 1, column: 12, offset: 11 }
// }

console.log(starTextEl.position);
// -> {
//   start: { line: 1, column: 6, offset: 5 },
//   end: { line: 1, column: 10, offset: 9 }     <-------- Expected end offset is 10
// }

console.log(
  doc.substring(
    emphasisEl.position.start.offset,
    emphasisEl.position.end.offset
  )
);
// -> _&#42;_

console.log(
  doc.substring(
    starTextEl.position.start.offset,
    starTextEl.position.end.offset
  )
);
// -> &#42     <----------------------------------- Expected: &#42;

Expected behavior

The position.end.offset of html entity escape should be after ;

Actual behavior

The position.end.offset of html entity escape is one less than expected.

Affected runtime and version

node@20.10.0

Affected package manager and version

npm@10.2.3

Affected OS and version

macOS Ventura 13.6.7

Build and bundle tools

webpack

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels May 27, 2024
@wooorm
Copy link
Member

wooorm commented May 27, 2024

Trying to make smaller reproductions, and different reproductions, it seems to be that the final ;, when it is the final thing in its parent (whether emphasis or strong or other), is not taken into account.

import assert from "node:assert/strict";
import { fromMarkdown } from "mdast-util-from-markdown";

const doc = "&amp;";
const tree = fromMarkdown(doc);

const paragraph = tree.children[0];
assert(paragraph.type === "paragraph");
const text = paragraph.children[0];
assert(text.type === "text");
assert(paragraph.position);
assert(text.position);

console.log(
  doc.slice(paragraph.position.start.offset, paragraph.position.end.offset)
);
// `&amp;`

console.log(doc.slice(text.position.start.offset, text.position.end.offset));
// `&amp`

@wooorm wooorm changed the title End offset of html entity is inaccurate Position of final ; in character reference not included in text that is ended by character reference May 27, 2024
@wooorm wooorm closed this as completed in 4aa8425 May 27, 2024

This comment has been minimized.

@wooorm wooorm added the 💪 phase/solved Post is done label May 27, 2024
@github-actions github-actions bot removed the 🤞 phase/open Post is being triaged manually label May 27, 2024
@wooorm
Copy link
Member

wooorm commented May 27, 2024

Thanks, released in 2.0.1!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💪 phase/solved Post is done
Development

No branches or pull requests

2 participants