-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Breck Yunits
authored and
Breck Yunits
committed
Apr 17, 2024
1 parent
9ffce38
commit 618da2a
Showing
2 changed files
with
89 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
linkifyParser | ||
description Use this to disable linkify on the text. | ||
extends abstractAftertextDirectiveParser | ||
cruxFromId | ||
cells keywordCell booleanCell | ||
|
||
linkTargetParser | ||
extends abstractHtmlAttributeParser | ||
description If you want to set the target of the link. To "_blank", for example. | ||
crux target | ||
cells keywordCell anyCell | ||
|
||
linkTitleParser | ||
description If you want to set the title of the link. | ||
crux title | ||
cells keywordCell | ||
catchAllCellType anyCell | ||
example | ||
* This report showed the treatment had a big impact. | ||
https://example.com/report This report. | ||
title The average growth in the treatment group was 14.2x higher than the control group. | ||
|
||
programLinkParser | ||
catchAllCellType codeCell | ||
|
||
linkParser | ||
extends abstractMarkupParser | ||
description Put the matching text in an <a> tag. | ||
cells keywordCell urlCell | ||
inScope linkTitleParser linkTargetParser commentParser | ||
programParser | ||
description Anything here will be URI encoded and then appended to the link. | ||
cruxFromId | ||
cells keywordCell | ||
catchAllParser programLinkParser | ||
javascript | ||
get encoded() { | ||
return encodeURIComponent(this.childrenToString()) | ||
} | ||
cruxFromId | ||
javascript | ||
tag = "a" | ||
get link() { | ||
const {baseLink} = this | ||
if (this.has("program")) | ||
return baseLink + this.getNode("program").encoded | ||
return baseLink | ||
} | ||
get baseLink() { | ||
const link = this.getWord(1) | ||
const isAbsoluteLink = link.includes("://") | ||
if (isAbsoluteLink) return link | ||
const relativePath = this.parent.compileSettings?.relativePath || "" | ||
return relativePath + link | ||
} | ||
get attributes() { | ||
const attrs = [`href="${this.link}"`] | ||
const options = ["title", "target"] | ||
options.forEach(option => { | ||
const node = this.getNode(option) | ||
if (node) attrs.push(`${option}="${node.content}"`) | ||
}) | ||
return attrs | ||
} | ||
patternStartsAtWord = 2 | ||
get pattern() { | ||
// If no pattern is provided, apply to the *entire* content. | ||
const words = this.getWordsFrom(this.patternStartsAtWord) | ||
return words.length ? words.join(" ") : this.parent.originalText | ||
} | ||
|
||
emailLinkParser | ||
description A mailto link | ||
crux email | ||
extends linkParser | ||
javascript | ||
get attributes() { | ||
return [`href="mailto:${this.link}"`] | ||
} | ||
|
||
quickLinkParser | ||
pattern ^https?\: | ||
extends linkParser | ||
cells urlCell | ||
javascript | ||
get link() { | ||
return this.firstWord | ||
} | ||
patternStartsAtWord = 1 |