|
wxMaxima
|
Implements the link detection declared in UrlDetection.h. More...
Functions | |
| std::vector< UrlSpan > | wxm::FindUrls (const wxString &text) |
| Finds every http://, https:// and mailto: link in a piece of text. | |
| bool | wxm::IsLaunchableUrl (const wxString &url) |
| Is this a link wxMaxima may hand to the web browser? | |
| wxString | wxm::ProtectUrls (const wxString &text, std::vector< wxString > &urls) |
| Replaces every link in a text by a placeholder an exporter won't touch. | |
| wxString | wxm::RestoreUrls (const wxString &text, const std::vector< wxString > &urls, const std::function< wxString(const wxString &)> &format) |
| Undoes ProtectUrls(), writing each link as format(url) returns it. | |
Implements the link detection declared in UrlDetection.h.
| std::vector< UrlSpan > wxm::FindUrls | ( | const wxString & | text | ) |
Finds every http://, https:// and mailto: link in a piece of text.
A link has to begin a word (so "xhttp://" is not one) and runs until the first character a URL may not contain unescaped: whitespace, or one of <>"{}|\^`. Punctuation that ends a sentence rather than the link (".,;:!?'") is left out, and so is a closing parenthesis or bracket that has no opening partner inside the link – "(see https://example.org)" links to "https://example.org", while a Wikipedia address ending in "_(physics)" keeps its parenthesis.
Since whitespace ends a link, a link never spans two lines: soft line breaks, which the text cells only ever put at spaces, can't split one.
Cheap enough to run on every restyle: a text without a ':' is rejected before anything else is looked at, and otherwise it is one linear pass.
| bool wxm::IsLaunchableUrl | ( | const wxString & | url | ) |
Is this a link wxMaxima may hand to the web browser?
Only http, https and mailto are allowed. A worksheet is a document from somewhere else, and letting a click in it launch a "file:" link, or one of the scheme handlers an operating system registers for its own programs, would let that document start things on the user's machine.
| wxString wxm::ProtectUrls | ( | const wxString & | text, |
| std::vector< wxString > & | urls | ||
| ) |
Replaces every link in a text by a placeholder an exporter won't touch.
The exporters escape a text cell's characters one kind at a time (LaTeX turns "_" into "\_", "%" into "\%", HTML "&" into "&", ...) and then run the result through the Markdown converter. A link must come out of that unchanged, so it is parked in urls and represented by a run of private-use characters and digits, which none of those steps change. RestoreUrls() puts it back, formatted as the exporter wants it.