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

Option to format placeholder value as Markdown link #465

Open
aecreations opened this issue Jun 16, 2024 · 2 comments
Open

Option to format placeholder value as Markdown link #465

aecreations opened this issue Jun 16, 2024 · 2 comments

Comments

@aecreations
Copy link
Owner

There is a limitation with placeholders where their default values cannot contain the following characters: []{}. These characters are reserved for the placeholder delimiters.

But these characters are commonly used in Markdown - in particular, to create hyperlinks, like this:

This is a sentence [with an embedded hyperlink](https://github.com/aecreations/clippings)!

...which is displayed as:

This is a sentence with an embedded hyperlink!

Placeholders with a default value containing Markdown-formatted hyperlinks won't cause the placeholder prompt to appear, and they will be inserted as is.

To work around this, the placeholder prompt dialog should detect if any placeholder values contain a URL, and format them accordingly when pasting.

For example, if a placeholder value that was entered into the placeholder prompt dialog is https://aecreations.io/clippings/index.php, the inserted text should be: [https://aecreations.io/clippings/index.php](https://aecreations.io/clippings/index.php). It would then render as:

https://aecreations.io/clippings/index.php

If the placeholder value contains a URL after it, enclosed in parentheses - e.g.: an embedded link(https://aecreations.io/clippings/index.php), the inserted text should be: [an embedded link](https://aecreations.io/clippings/index.php), which would be rendered as:

an embedded link

What if there is text before and after the link? Perhaps the placeholder value could be formatted like so:

This is a sample clipping with an ::embedded link(https://aecreations.io/clippings/index.php) in the sentence.

...where the double colon indicates the start of the hyperlink display text. The above would then convert to: This is a sample clipping with an [embedded link](https://aecreations.io/clippings/index.php) in the sentence., and be rendered as:

This is a sample clipping with an embedded link in the sentence.

When placeholder values are detected with the above formatting patterns, upon clicking OK in the placeholder prompt, open a modal dialog within the placeholder prompt window asking the user if the URLs should be formatted as Markdown links:

A web address was detected in the placeholder value. Format as a Markdown link?
< Yes>  < No >
A web address was detected in one or more placeholder values. Format as Markdown links?
< Yes>  < No >

There should be a checkbox option (default turned on) in Clippings preferences (Paste tab) to enable this functionality:

[X] Ask if placeholder values containing web addresses should be formatted as Markdown links
@aecreations
Copy link
Owner Author

Beginning in Firefox 134, a new static method, RegExp.escape() can escape characters in regular expressions:

The RegExp.escape() static method escapes any potential regex syntax characters in a string, and returns a new string that can be safely used as a literal pattern for the RegExp() constructor.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/escape

@aecreations
Copy link
Owner Author

Test Clippings containing Markdown:
markdown.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant