diff options
| author | Shulhan <ms@kilabit.info> | 2021-12-06 18:37:49 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2021-12-06 18:37:49 +0700 |
| commit | 51c845f8b738fba508f99dc7c7400d11f65bd12d (patch) | |
| tree | 54f89d4c995938b9eb55b34847430eea39cf7117 /inline_parser.go | |
| parent | d0ebdcaeaa5c52b7ff8513d1a324607e104ead3c (diff) | |
| download | asciidoctor-go-51c845f8b738fba508f99dc7c7400d11f65bd12d.tar.xz | |
all: fix parsing and rendering cross reference
Previously, when parsing cross reference we assume that if the string
contains upper-case letter then it's a label so we store it as title
to search for ID later.
The bug is when ID is set manually and its contains upper-case for
example "[#Id]".
This changes fix this issue by storing cross reference first, not
assuming it as ID or title, and then when doing rendering we check
whether its ID or title.
Diffstat (limited to 'inline_parser.go')
| -rw-r--r-- | inline_parser.go | 33 |
1 files changed, 4 insertions, 29 deletions
diff --git a/inline_parser.go b/inline_parser.go index 872a669..401c6b6 100644 --- a/inline_parser.go +++ b/inline_parser.go @@ -414,45 +414,20 @@ func (pi *inlineParser) parseCrossRef() bool { var ( href string label string - title string - ok bool ) parts := bytes.Split(raw, []byte(",")) + href = string(parts[0]) if len(parts) >= 2 { label = string(bytes.TrimSpace(parts[1])) } - if isRefTitle(parts[0]) { - // Get ID by title. - href, ok = pi.doc.titleID[string(parts[0])] - if ok { - if len(label) == 0 { - label = string(parts[0]) - } - } else { - // Store the label for cross reference later. - title = string(parts[0]) - } - } else if isValidID(parts[0]) { - href = string(parts[0]) - if len(label) == 0 { - anchor := pi.doc.anchors[href] - if anchor != nil { - label = anchor.label - } - } - } else { - return false - } - - // The ID field will we non-empty if href is empty, it will be - // revalidated later when rendered. + // Set attribute href to the first part, we will revalidated later + // when rendering the element. elCrossRef := &element{ elementAttribute: elementAttribute{ Attrs: map[string]string{ - attrNameHref: href, - attrNameTitle: title, + attrNameHref: href, }, }, kind: elKindCrossReference, |
