-
Notifications
You must be signed in to change notification settings - Fork 0
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
Foreword (Whalen): Long URL in citation #32
Comments
FYI there are other instances of long citations in the pop-ups. |
I can use this |
@geealbers before I make changes with the above fix, I want to check and see if there is a less time-consuming/manual way to approach this. |
I've fixed this and am closing the issue, but wanted to document the solution here. Rather than manually inserting /**
* Insert zero-width space with punctuation for better line breaks in URLs
* per Chicago Manual of Style
*/
markdownLibrary.renderer.rules.link_open = (tokens, idx, options, env, self) => {
const linkTextIndex = idx + 1
const breakAfter = /([[\/]{2}|:])/g // double-slash and colon
const breakBefore = /([(?<!\/)\/(?!\/)|~|\.|,|_|?|#|%|=|+|&|-])/g // single-slash and others
const breakCharacter = '' // zero-width space
const linkText = tokens[linkTextIndex].content
.replace(breakAfter, '$1' + breakCharacter)
.replace(breakBefore, breakCharacter + '$1')
tokens[linkTextIndex].content = linkText
return defaultRender(tokens, idx, options, env, self)
} One potentially significant issue with either method (manually adding To address the copying issue, I add another small script (aedb04c) that uses the Clipboard API to strip out the zero-width spaces from the text that's being copied /**
* @description
* When a reader copies a URL, this removes the break character that was inserted
* as a markdown rendering rule in _plugins/markdown/index.js for better URL line breaks
* https://developer.mozilla.org/en-US/docs/Web/API/Element/copy_event
*/
function copyURL() {
const links = document.querySelectorAll("a");
const breakCharacter = '' // zero-width space
for (let i = 0; i < links.length; i++) {
links[i].addEventListener("copy", event => {
const selection = document.getSelection();
event.clipboardData.setData("text/plain", selection.toString().replaceAll(breakCharacter, ''));
event.preventDefault();
})
}
} |
The text was updated successfully, but these errors were encountered: