Skip to content

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

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'develop' into github-callouts
  • Loading branch information
Koooooo-7 authored Sep 12, 2024
commit 64f5a92ca2aa6f9f6fe6fd3b15816dc426c2a3e1
37 changes: 6 additions & 31 deletions src/core/render/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,37 +157,12 @@ export class Compiler {
// Supports mermaid
const origin = {};

/**
* Render anchor tag
* @link https://github.com/markedjs/marked#overriding-renderer-methods
* @param {String} tokens the content tokens
* @param {Number} depth Type of heading (h<level> tag)
* @returns {String} Heading element
*/
origin.heading = renderer.heading = function ({ tokens, depth }) {
const text = this.parser.parseInline(tokens);
let { str, config } = getAndRemoveConfig(text);
const nextToc = { depth, title: str };

const { content, ignoreAllSubs, ignoreSubHeading } =
getAndRemoveDocsifyIgnoreConfig(str);
str = content.trim();

nextToc.title = removeAtag(str);
nextToc.ignoreAllSubs = ignoreAllSubs;
nextToc.ignoreSubHeading = ignoreSubHeading;
const slug = slugify(config.id || str);
const url = router.toURL(router.getCurrentPath(), { id: slug });
nextToc.slug = url;
_self.toc.push(nextToc);

// Note: tabindex="-1" allows programmatically focusing on heading
// elements after navigation. This is preferred over focusing on the link
// within the heading because it matches the focus behavior of screen
// readers when navigating page content.
return `<h${depth} id="${slug}" tabindex="-1"><a href="${url}" data-id="${slug}" class="anchor"><span>${str}</span></a></h${depth}>`;
};

// Renderer customizers
origin.heading = headingCompiler({
renderer,
router,
compiler: this,
});
origin.blockquoteCompiler = blockquoteCompiler({ renderer });
origin.code = highlightCodeCompiler({ renderer });
origin.link = linkCompiler({
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.