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

feat: Clickable web uri in footnote #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Configuration/Settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@ Neos:
resource: resource://Psmb.Footnote/Public/JavaScript/Footnote/Plugin.js
fusion:
autoInclude:
Psmb.Footnote: true
Psmb.Footnote: true

Psmb:
Footnote:
autoLinking: false
nl2br: false
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,13 @@ prototype(Neos.Neos:PrimaryContent) {
border-bottom: orange solid 1px;
}
```

6. Optionnally it is possible to disable the detection of web uri in order to not make them clickable. And disabling line break substition too.


```
Psmb:
Footnote:
autoLinking: true
nl2br: true
```
45 changes: 42 additions & 3 deletions Resources/Private/Fusion/Root.fusion
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ prototype(Psmb.Footnote:FootnoteProcessor) < prototype(Neos.Fusion:Array) {
value = ${value}
@process.parse = Psmb.Footnote:PregReplaceCallback {
@if.notInBackend = ${!documentNode.context.inBackend}
pattern = ${'/<span data-footnote="(.*?)">(.*?)<\/span>/'}
pattern = ${'/<span data-footnote="([^"]+)">([^<]+)<\/span>/'}
subject = ${value}
replacementRenderer = ${matches[2] + '<sup class="footnote" id="footnoteSource_' + iterator.cycle + '"><a href="#footnote_' + iterator.cycle + '">' + iterator.cycle + '</a></sup>'}
}
Expand All @@ -20,10 +20,49 @@ prototype(Psmb.Footnote:FootnoteProcessor) < prototype(Neos.Fusion:Array) {
@if.live = ${node.context.workspaceName == 'live'}
@process.wrap = ${value && '<ul class="footnoteList">' + value + '</ul>'}
collection = Psmb.Footnote:PregMatchAll {
pattern = ${'/<span data-footnote="(.*?)">(.*?)<\/span>/'}
pattern = ${'/<span data-footnote="([^"]+)">([^<]+)<\/span>/'}
subject = ${value}
}
itemName = 'item'
itemRenderer = ${'<li class="footnoteList-item" id="footnote_' + iterator.cycle + '"><a href="#footnoteSource_' + iterator.cycle + '"><sup>' + iterator.cycle + '</sup></a> ' + item[1] + '</li>'}
itemRenderer = Psmb.Footnote:FootnoteProcessor.ItemRenderer
}
}

prototype(Psmb.Footnote:FootnoteProcessor.ItemRenderer) < prototype(Neos.Fusion:Case) {
autoLinking {
condition = ${Configuration.setting('Psmb.Footnote.autoLinking') == true}
renderer = Psmb.Footnote:FootnoteProcessor.LinkRenderer
}
default {
condition = ${true}
renderer = Psmb.Footnote:FootnoteProcessor.ListItemRenderer
}
}

# Detect URI to make it clickable
prototype(Psmb.Footnote:FootnoteProcessor.LinkRenderer) < prototype(Neos.Fusion:Value) {
element = ${item[1]}
element.@process {
linkUrl = Psmb.Footnote:PregReplaceCallback {
pattern = ${'#(https?:\/\/[^\s]+)#'}
subject = ${value}
replacementRenderer = ${'<a href="' + matches[1] + '">' + matches[1] + '</a>'}
}
lineBreak = ${Configuration.setting('Psmb.Footnote.nl2br') == true ? String.nl2br(value) : value}
}
@context.element = ${this.element}
value = Psmb.Footnote:FootnoteProcessor.ListItemRenderer
}

prototype(Psmb.Footnote:FootnoteProcessor.ListItemRenderer) < prototype(Neos.Fusion:Component) {
element = ${String.isBlank(element) == false ? element : item[1]}
id = ${'footnote_' + iterator.cycle}
anchor = ${'#footnoteSource_' + iterator.cycle}
index = ${iterator.cycle}

renderer = afx`
<li class="footnoteList-item" id={props.id}>
<a href={props.anchor}><sup>{props.index}</sup></a>{props.element}
</li>
`
}