Skip to content

Commit

Permalink
Revert "Changed parsing code for links/images."
Browse files Browse the repository at this point in the history
This reverts commit 1b5425c.

See #64.
  • Loading branch information
jgm committed Oct 7, 2023
1 parent ee172ef commit 8a32edc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 52 deletions.
70 changes: 25 additions & 45 deletions src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -569,12 +569,7 @@ const parse = function(input: string, options: ParseOptions = {}): Doc {
},

["-linktext"]: (suffixes, startpos, endpos, pos) => {
const node = popContainer(pos); // the container added by +linktext/+imagetext
addChildToTip({
tag: "link",
destination: "",
children: node.children,
pos: node.pos});
// we don't pop yet, but wait for -destination
},

["+imagetext"]: (suffixes, startpos, endpos, pos) => {
Expand All @@ -583,56 +578,41 @@ const parse = function(input: string, options: ParseOptions = {}): Doc {
},

["-imagetext"]: (suffixes, startpos, endpos, pos) => {
const node = popContainer(pos); // the container added by +linktext/+imagetext
addChildToTip({
tag: "image",
destination: "",
children: node.children,
pos: node.pos});
// we don't pop yet, but wait for -destination
},

["+destination"]: (suffixes, startpos, endpos, pos) => {
pushContainer(pos);
topContainer().data.startDestination = endpos;
context = Context.Literal;
},

["-destination"]: (suffixes, startpos, endpos, pos) => {
const node = popContainer(pos);
const txt = input.substring(node.data.startDestination + 1, startpos);
if (containers.length > 0) {
const tip = containers[containers.length - 1];
// the container added by +linktext or +imagetext
const lastchild = tip.children[tip.children.length - 1];
if (lastchild) {
lastchild.destination = lastchild.destination +
txt.replace(/[\r\n]+/g,"").replace(/[\\](['!\"#$%&\\'()\\*+,\-\.\/:;<=>?@\[\]\^_`{|}~'])/g,"$1");
}
}
["-destination"]: (suffixes, startpos, endpos, pos) => {
const node = popContainer(pos); // the container added by +linktext/+imagetext
addChildToTip({
tag: node.data.isimage ? "image" : "link",
destination: accumulatedText.replace(/[\r\n]/g,""),
children: node.children,
pos: node.pos});
context = Context.Normal;
accumulatedText = "";
},

["+reference"]: (suffixes, startpos, endpos, pos) => {
pushContainer(pos);
topContainer().data.startReference = endpos;
context = Context.Literal;
},

["-reference"]: (suffixes, startpos, endpos, pos) => {
const node = popContainer(pos);
const txt = normalizeLabel(input.substring(node.data.startReference + 1, startpos));
if (containers.length > 0) {
const tip = containers[containers.length - 1];
// the container added by +linktext or +imagetext
const lastchild = tip.children[tip.children.length - 1];
if (lastchild) {
if (lastchild.reference === undefined) {
lastchild.reference = "";
}
let ref = txt.replace(/[\r\n]+/g," ").replace(/[\\](['!\"#$%&\\'()\*+,\-\.\/:;<=>?@\[\]\^_`{|}~'])/g,"$1");
if (ref.length === 0) {
ref = getStringContent(lastchild);
}
lastchild.reference = lastchild.reference + ref;
}
}
const node = popContainer(pos); // the container added by +linktext
let ref = accumulatedText;
if (ref.length === 0) {
ref = getStringContent(node);
}
addChildToTip({
tag: node.data.isimage ? "image" : "link",
reference: normalizeLabel(ref),
children: node.children,
pos: node.pos});
context = Context.Normal;
accumulatedText = "";
},

["+verbatim"]: (suffixes, startpos, endpos, pos) => {
Expand Down
7 changes: 0 additions & 7 deletions test/regression.test
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,3 @@ doc
str text="2"
```

Issue #46:

```
[hi]({#ab})
.
<p><a href="{#ab}">hi</a></p>
```

0 comments on commit 8a32edc

Please sign in to comment.