Repository navigation
Add support for more characters in links - #379
Conversation
This commit excludes support for both `)` and `]` out of concern that parenthesized URLs fail to parse. In that case, are recommended to use the `link` function.
|
Do you have a source on what constitutes a valid URL? |
|
Correct URL parsing is notoriously complex, which is why I only added some remaining characters found in URLs. However, here you go: https://url.spec.whatwg.org |
|
This will also allow direct links to IPv6s, etc. We generally aim to keep automatic link recognition narrow to avoid false positives. You can always use the link function explicitly! Do you think it's worth it to keep all of these extra characters in here or should this PR be narrowed down in that respect? |
|
I have now added a bit of common punctuation which a link can't end with. I assume with that change, false positives should be relatively rare. Nevertheless, one caveat here would be the trailing question mark. URLs may end with them and still be perfectly valid. I think that is actually not a rare occurance. Unfortunately, this solution will still not allow IPv6 addresses in links, because closing brackets are excluded from the list of allowed characters. Wikipedia links especially will also often not be parsed correctly as it is.
I can think of one heuristic that should work pretty well. That is, require an opening parenthesis for every closing parenthesis. My only real worry here is that the parsing would become too complex. Alternatively, we could bypass this discussion completely, by just not having any special link syntax and requiring users to use |
|
IMO the ability to just copy-paste a link into a document and have it work is still great, even if it fails in obscure cases. That said, I'd also remove
Ideally, there would be a warning that the link isn't parsed as the user might expect it, but I don't know whether typst has the infrastructure for warnings yet. |
|
Good points! I think I will tweak the behaviour to be in line with your suggestion if the "heuristic" approach isn't chosen. Regarding that, what's your opinion on it? |
|
The heuristic should probably be fine? Theory states that lexers should use regular grammars, which is good for simple regex-based syntax highlighters. Though I quickly checked, and the VS code terminal recognizes closing parens in links if there was at least one open paren, but doesn't check for proper nesting. gnome-terminal checks for proper nesting. MS Word tries to be smart with editing, and ends up being confusing, so no idea what its precise rules are. Parens in URLs seem to be common enough that all the above tools have special rules to handle them somewhat-smartly, so it's probably a good idea to follow their lead. Edit: Requiring properly nested parens, like you suggested, should be the most correct way to do it, to make sure it doesn't conflict with other syntax features. |
|
Checking paren nesting seems sensible to me. |
|
I have now implemented bracket-nesting respecting behavior. |
|
Thanks! |
Squashed port of the 14-commit fork/feat/memory-optimization-stack onto upstream typst/main at 86e3843. Same content as the previous fork branch (detailed history preserved on fork/feat/memory-optimization-stack and the experimental-2x-pdf branch); this commit replays the work onto the current upstream so the PR base is clean. Notable rebase fixups: - typst-library: take upstream's moxcms-based color.rs (replaces qcms); drop qcms workspace dep, add moxcms. - typst-pdf/convert.rs: handle krilla's new KrillaError::DuplicateNamedDestination variant (upstream PR typst#379); consume register_named_destination's must_use return. - typst/src/lib.rs: Phase 2 streaming Engine construction switched from `routines: &ROUTINES` to `library` field (upstream PR typst#8215 request-stdlib-from-world-once). - typst-library/foundations/styles.rs: import FxHashMap. - pages/mod.rs: drop unused Routines import; merge upstream's slimmed import block with our streaming-layout-mode imports (At, Resolve, etc.). - Bump krilla pin to gpradofe/krilla@6bcead6 (rebased streaming-tag branch). - Drop unused [patch.crates-io] entry for pdf-writer; the renumber/io extensions in our pdf-writer fork are not consumed by the current typst-pdf code path. - tests/ref/{pdf,svg}/hashes.txt regenerated against new upstream. Verification: - cargo build --release: clean. - cargo test --release -p typst-tests: 3421/0 (parity with the previous rebased state at fork.4). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
This PR allows additional characters to be part of a link.
It excludes support for both
)and]out of concern that parenthesized URLs would fail to parse.In that case, users are recommended to make use of the
linkfunction.