-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
feat: GitHub style callouts #2487
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
base: develop
Are you sure you want to change the base?
Changes from 1 commit
f9950e0
f9a9869
db423b6
6cf5f36
72627ed
ee73d59
81c1dd0
26240d3
3501b04
64f5a92
543e35d
fea3b1b
88e32ff
9a27faa
3607c8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,36 @@ | ||||||
export const blockquoteCompiler = ({ renderer }) => | ||||||
(renderer.blockquote = function ({ tokens }) { | ||||||
const calloutData = | ||||||
tokens[0].type === 'paragraph' && | ||||||
// 0: Match "[!TIP] My Title" | ||||||
// 1: Mark "[!TIP]" | ||||||
// 2: Type "TIP" | ||||||
tokens[0].raw.match(/^(\[!(\w+)\])/); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think we need strict match the callout tags in case of users use something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was intentional. :) Callouts (or "admonitions" or "alerts") are found in many other apps and the list of callouts supported is often much larger than what GitHub supports. By capturing the string contained with the brackets ( For example: > [!BUG]
> This is a bug callout .callout.bug {
--callout-bg: orange;
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. so it means the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct. The callout.question {
--callout-bg: red;
--callout-color: white;
} I can add a note about custom classes to the docs along with a note explaining that in most cases custom classes will not work outside of Docsify. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. great! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Hi, @jhildenbiddle Do you still need to modify the document? If not, then you can merge this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sy-records Yep. Haven't had a chance to complete the updated docs, but I'll have that in the next or two. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One other enhancements I'd like to make is the ability to define localized labels. I make a conscious decision to not implement this initially for a few reasons, but after thinking it over for a bit I've decided it makes sense to offer this feature. The implementation will follow the same pattern we've used elsewhere in our configuration. The default behavior will be to not render text labels (as shown in screenshots above): window.$docsify = {
// Default: do not render text labels
callouts: {},
}; If users want to render text labels automatically as is done in markdown environments like GitHub and Obsidian, they can define them as part of their configuration: window.$docsify = {
// Render same label for all route paths
callouts: {
caution: 'Caution',
important: 'Important',
note: 'Note',
tip: 'Tip',
warning: 'Warning',
},
}; window.$docsify = {
// Render localized labels based on route paths
callouts: {
caution: {
'/es/': 'Precaución',
'/de-de/': 'Vorsicht',
'/ru-ru/': 'Осторожность',
'/zh-cn/': '警告',
'/': 'Caution',
},
// ...
},
}; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ----- @jhildenbiddle , Currently, we simply add a icon per callout config. That looks good to me. I don't propose that we need introduce a
window.$docsify = {
// Render same label for all route paths
callouts: {
example: {
'/zh-cn/': '例子',
'/': 'Example',
},
}, It makes the config more complex and messy, they need config options size is: IMO, the The only different thing is we introduce some If user do wanna enrich the
Besides. Which means, user could just know something like:
Then, they can append all the extra info for the
|
||||||
|
||||||
let openTag = '<blockquote>'; | ||||||
let closeTag = '</blockquote>'; | ||||||
|
||||||
if (calloutData) { | ||||||
const calloutMark = calloutData[1]; // "[!TIP]" | ||||||
const calloutType = calloutData[2].toLowerCase(); // "tip" | ||||||
const token = tokens[0].tokens[0]; | ||||||
|
||||||
// Remove callout mark from tokens | ||||||
['raw', 'text'].forEach(key => { | ||||||
token[key] = token[key].replace(calloutMark, '').trimStart(); | ||||||
}); | ||||||
|
||||||
// Remove empty paragraph | ||||||
if (tokens.length > 1 && !token.raw.trim()) { | ||||||
tokens = tokens.slice(1); | ||||||
} | ||||||
|
||||||
openTag = `<div class="callout ${calloutType}">`; | ||||||
closeTag = `</div>`; | ||||||
} | ||||||
|
||||||
const body = this.parser.parse(tokens); | ||||||
const html = `${openTag}${body}${closeTag}`; | ||||||
|
||||||
return html; | ||||||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be great to add a
console.warn
when the respective piece of code runs, so people will know. We could also tell people to use major versions in deprecation messages, to start to get versionless people knowing what will be happening, so they can prepare. Wdyt?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Easy enough. Happy to add it. I may consolidate console deprecation warnings as well so they are easier to track and the output can be standardized.
This one may introduce some false positives simply because of the many different ways Docsify can be loaded, but I think a simple search for a
<script>
tag with asrc
value that matches the following criteria could work:.com
,.net
,.org
, etc.)\\docsify(\.min)?\.js
@version/
and/version/
CDN URLs)This would match the following URLs and trigger the console warning:
The following URLs would be ignored:
FWIW, I may opt to implement this in a separate PR. Replying here for convenience. :)
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per the experience of I work the compatibility release, it seems too complicated for us to handle too much cases.
If we can ensure that we notify as many people as possible who will be affected, notifying additional people who may not be impacted is acceptable.
So I suppose we could make the
versionDetector
simply like this:Firstly, We check some common CDN providers (unpack, jsdelivr) import path format with versions.
Then, for other importing cases, we only try to find the
docsify.min.js
and thedocsify.js
content. No matter what the path folder/5/
nor the domain is, cos we don't know how users host docsify on which server, which place, which ip, which domain, which CDN...As long as it retrieves new docsify resources without versioning, it gets caught by theversionDetector
.When the site contains either resources name of them (
docsify.min.js
/docsify.js
), we throw out a warning such as:Conclusion:
If users import the resource online (host site on a domain or a raw IP are both okay ), they would get the warning.
If users deploy docsify internally or locally, they won't get a docsify warning, cos they won't get any docsify update also. version control doesn't matter for them. Once they manually upgrade docsify with
versionDetector
, they would get the warning then.Besides, we provide a
versionDetector
config to manually suppress the warning and checking, when they don't care about any breaking changes or the resource import place is not a generic resources versioning control path (e.g. https://dontblameme.com/libs/update/20240401/docsify.min.js).or am I too straightforward?