Skip to content

Commit

Permalink
feat(Table of Contents feature): Remove specific strings from table o…
Browse files Browse the repository at this point in the history
…f contents #49 / Update button
  • Loading branch information
YU000jp committed Jan 20, 2024
1 parent 0d8a74e commit 01569f4
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
12 changes: 12 additions & 0 deletions src/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,15 @@ export async function removeProperties(tocBlocks: TocBlock[], i: number, blockCo
}
return blockContent
}

export const removeListWords = (blockContent: string): string => {
//改行区切りのリスト
//最後の改行を削除する
const list = (logseq.settings!.tocRemoveWordList as string).split("\n")
//リストにマッチする文字列を正規表現で取り除く
for (let i = 0; i < list.length; i++) {
if (list[i] === "") continue
blockContent = blockContent.replaceAll(new RegExp(list[i], "g"), "")
}
return blockContent
}
9 changes: 9 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ export const settingsTemplate = (): SettingSchemaDesc[] => [
default: false,
description: "default: false",
},
//20240120
{//Table of Contents、削除する単語リスト 改行区切り
key: "tocRemoveWordList",
title: t("Remove words from table of contents"),
type: "string",
inputAs: "textarea",
default: "",
description: t("Separate with line breaks"),
},
{//wide viewモード、Journal Queriesを表示するかどうか
key: "booleanWideModeJournalQueries",
title: t("Showing journal queries on today journal page"),
Expand Down
23 changes: 18 additions & 5 deletions src/toc.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import removeMd from "remove-markdown"
import { BlockEntity } from "@logseq/libs/dist/LSPlugin.user"
import { removeProperties, removeMarkdownLink, removeMarkdownAliasLink, replaceOverCharacters, removeMarkdownImage } from "./markdown"
import { removeProperties, removeMarkdownLink, removeMarkdownAliasLink, replaceOverCharacters, removeMarkdownImage, removeListWords } from "./markdown"
import { displayToc } from "."


export function tocContentTitleCollapsed(PageName: string) {
Expand Down Expand Up @@ -99,13 +100,23 @@ export const getTocBlocks = (childrenArr: Child[]): TocBlock[] => {

export const headersList = async (targetElement: HTMLElement, tocBlocks: TocBlock[], thisPageName: string): Promise<void> => {

// To top
const elementTop = document.createElement("div")
const elementButtons = document.createElement("div")
// Update button
const elementUpdate = document.createElement("span")
elementUpdate.classList.add("cursor")
elementUpdate.innerHTML = "🔄 Update"
elementUpdate.style.padding = "1em"
elementButtons.append(elementUpdate)
elementUpdate.addEventListener('click', () => displayToc(thisPageName), { once: true })
elementButtons.append(document.createElement("span").innerHTML = "/")
// Scroll to top
const elementTop = document.createElement("span")
elementTop.classList.add("cursor")
elementTop.innerHTML = "To top ⬆️"
elementTop.innerHTML = "⬆️ Scroll to top"
elementTop.style.padding = "1em"
targetElement.append(elementTop)
elementButtons.append(elementTop)
elementTop.addEventListener('click', () => parent.document.querySelector("body[data-page=\"page\"]>div#root>div>main div#main-content-container h1.page-title")!.scrollIntoView({ behavior: 'smooth' }))
targetElement.append(elementButtons)

// Create list
for (let i = 0; i < tocBlocks.length; i++) {
Expand Down Expand Up @@ -141,6 +152,8 @@ export const headersList = async (targetElement: HTMLElement, tocBlocks: TocBloc
blockContent = replaceOverCharacters(blockContent)
//マークダウンの画像記法を全体削除する
blockContent = removeMarkdownImage(blockContent)
//リストにマッチする文字列を正規表現で取り除く
blockContent = removeListWords(blockContent)

// Header
if (blockContent.startsWith("# ")
Expand Down
6 changes: 5 additions & 1 deletion src/wide.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ body[data-page="page"] {

&#tocInPage {
font-size: .86em;
padding-bottom: 2em;
padding-bottom: 1.6em;
padding-left: 0.3em;
padding-right: 1.3em;
padding-top:1em;
user-select: none;

&>div{
margin-bottom: 1.2em;
}
& h1,
& h2,
& h3,
Expand Down

0 comments on commit 01569f4

Please sign in to comment.