Skip to content

Commit

Permalink
feat: remove list format rendering in heading
Browse files Browse the repository at this point in the history
  • Loading branch information
guopenghui committed Oct 14, 2023
1 parent 89135a8 commit 314fa25
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 46 deletions.
36 changes: 1 addition & 35 deletions main.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-quiet-outline",
"name": "Quiet Outline",
"version": "0.3.16",
"version": "0.3.17",
"minAppVersion": "0.15.6",
"description": "Make outline quiet and more powerful, including no-auto-expand, rendering heading as markdown, and search support.",
"author": "the_tree",
Expand Down
11 changes: 8 additions & 3 deletions src/Outline.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { Icon } from '@vicons/utils';
import { SettingsBackupRestoreRound, ArrowCircleDownRound } from '@vicons/material';
import { marked } from 'marked';
import { formula, internal_link, highlight, tag, remove_href, renderer, remove_ref } from './parser';
import { formula, internal_link, highlight, tag, remove_href, renderer, remove_ref, nolist } from './parser';
import { store } from './store';
import { QuietOutline } from "./plugin";
Expand Down Expand Up @@ -190,9 +190,14 @@ let handleScroll = debounce(_handleScroll, 100);
function _handleScroll(evt: Event) {
let target = evt.target as HTMLElement;
if (!target.classList.contains("markdown-preview-view") && !target.classList.contains("cm-scroller")) {
if (!target.classList.contains("markdown-preview-view") &&
!target.classList.contains("cm-scroller") &&
// fix conflict with outliner
// https://github.com/guopenghui/obsidian-quiet-outline/issues/133
!target.classList.contains("outliner-plugin-list-lines-scroller")) {
return;
}
// const view = plugin.app.workspace.getActiveViewOfType(MarkdownView);
const view = plugin.current_note;
Expand Down Expand Up @@ -438,7 +443,7 @@ function arrToTree(headers: HeadingCache[]): TreeOption[] {
// render markdown
marked.use({ extensions: [formula, internal_link, highlight, tag, remove_ref] });
marked.use({ extensions: [formula, internal_link, highlight, tag, remove_ref, nolist] });
marked.use({ walkTokens: remove_href });
marked.use({ renderer });
Expand Down
55 changes: 48 additions & 7 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,55 @@ export const remove_href = (token: marked.Token) => {

// remove <ol>
export const renderer = {
list(body: string, ordered: boolean, start: number) {
if (ordered)
return `<p>${start}. ${body}</p>`;
else
return `<p>${body}</p>`;
},
listitem(text: string, task: boolean, checked: boolean) {
return `${text}`;
}

};
};

// remove list format rendering
export const nolist: Extension = {
name: "nolist",
level: "block",
start(src) {
return src.match(/^([+\-*]|\d+\.) /)?.index
},
tokenizer(src, tokens) {
const rule = /^(([+\-*])|(\d+)\.) (.*)/;
const match = rule.exec(src);
let token = undefined;
if (match && match[2]) {
token = {
type: "nolist",
raw: match[0],
ordered: false,
marker: match[2],
start: "",
body: match[4],
tokens: [],
};
} else if (match && match[3]) {
token = {
type: "nolist",
raw: match[0],
ordered: true,
marker: "",
start: match[3],
body: match[4],
tokens: [],
};
}

token && this.lexer.inline(token.body, token.tokens);

return token;
},
renderer(token) {
let body = this.parser.parseInline(token.tokens, null);

if (token.ordered)
return `<p>${token.start}. ${body}</p>`;
else
return `<p>${token.marker} ${body}</p>`;
}
}

0 comments on commit 314fa25

Please sign in to comment.