Skip to content

Commit

Permalink
Maintain the 'if it looks like sufficiently close to a link, treat it…
Browse files Browse the repository at this point in the history
… as one' behavior.
  • Loading branch information
tabatkins committed Mar 19, 2024
1 parent 140edc3 commit 29314d1
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions bikeshed/h/parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,29 +978,42 @@ def parseCSSMaybe(s: Stream, start: int) -> Result[list[ParserNode]]:
)
return Result([startTag, tagMiddle, endTag], nodeEnd)

# Probably a valid link, but *possibly* not,
# so keep the text as-is, but set the intended link text
# if it *does* succeed.
# Probably a valid link, but *possibly* not.
# If it looks *sufficiently like* an autolink,
# swap the text out as if it was one
# (has a for value and/or a type value, and the for value
# doesn't look like it's an end tag).
# Otherwise, keep the text as-is, but set the intended
# link text if it *does* succeed.
startTag = StartTag(
line=s.line(start),
endLine=s.line(textStart),
tag="a",
attrs={
"bs-autolink-syntax": s[start:nodeEnd],
"bs-replace-text-on-link-success": valueName,
"class": "css",
"data-link-type": linkType,
"data-lt": valueName,
},
)
if for_:
startTag.attrs["data-link-for"] = for_
if (for_ is not None and not for_.endswith("<")) or match[3] is not None:
tagMiddle = SafeText(
line=s.line(textStart),
endLine=s.line(textEnd),
text=valueName,
)
else:
startTag.attrs["bs-replace-text-on-link-success"] = valueName
tagMiddle = SafeText(
line=s.line(textStart),
endLine=s.line(textEnd),
text=text,
)


startTag.finalize()
tagMiddle = SafeText(
line=s.line(textStart),
endLine=s.line(textEnd),
text=text,
)
endTag = EndTag(
line=s.line(textEnd),
endLine=s.line(nodeEnd),
Expand Down

0 comments on commit 29314d1

Please sign in to comment.