MCPcopy Create free account
hub / github.com/almariah/embed-code-file / addTitle

Method addTitle

main.ts:108–140  ·  view source on GitHub ↗
(el: HTMLElement, context: MarkdownPostProcessorContext)

Source from the content-addressed store, hash-verified

106 }
107
108 addTitle(el: HTMLElement, context: MarkdownPostProcessorContext) {
109 let codeElm = el.querySelector('pre > code')
110 if (!codeElm) {
111 return
112 }
113
114 const pre = codeElm.parentElement as HTMLPreElement;
115
116 const codeSection = context.getSectionInfo(pre)
117 if (!codeSection) {
118 return
119 }
120
121 const view = app.workspace.getActiveViewOfType(MarkdownView)
122 if (!view) {
123 return
124 }
125
126 const num = codeSection.lineStart
127 const codeBlockFirstLine = view.editor.getLine(num)
128
129 let matchTitle = codeBlockFirstLine.match(/TITLE:\s*"([^"]*)"/i)
130 if (matchTitle == null) {
131 return
132 }
133
134 const title = matchTitle[1]
135 if (title == "") {
136 return
137 }
138
139 this.insertTitlePreElement(pre, title)
140 }
141
142 insertTitlePreElement(pre: HTMLPreElement, title: string) {
143 pre

Callers 1

onloadMethod · 0.95

Calls 1

insertTitlePreElementMethod · 0.95

Tested by

no test coverage detected