@@ -14,6 +14,8 @@ export interface Doc {
1414}
1515
1616export const useDocs = createGlobalState ( ( ) => {
17+ // const router = useRouter()
18+
1719 return useAsyncState ( async ( ) => {
1820 const res = await fetch ( "/docs/docs.yaml" )
1921 const data = await res . text ( )
@@ -24,21 +26,187 @@ export const useDocs = createGlobalState(() => {
2426 . then ( res => res . text ( ) ) ) ,
2527 )
2628
27- marked . use ( {
28- renderer : {
29- blockquote ( { tokens } ) {
30- const text = this . parser . parse ( tokens )
31- return `<blockquote class="d-block px-4 py-6 border-s-lg border-primary bg-surface mb-4 overflow-auto" style="--v-border-opacity: 1;">${ text } </blockquote>`
32- } ,
33- } ,
34- } )
29+ const renderer = new marked . Renderer ( )
30+
31+ renderer . heading = function ( { depth, tokens } ) {
32+ const content = this . parser . parseInline ( tokens )
33+ const lv = Math . min ( depth + 3 , 6 )
34+ return `<h${ lv } class="text-h${ lv } mb-2">${ content } </h${ lv } >`
35+ }
36+
37+ renderer . paragraph = function ( { tokens } ) {
38+ const content = this . parser . parseInline ( tokens )
39+ return `<p class="text-body-1 text-accent mt-2 mb-4">${ content } </p>`
40+ }
41+
42+ renderer . listitem = function ( x ) {
43+ // console.log(x.tokens)
44+
45+ // return "item"
46+ const content = this . parser . parse ( x . tokens )
47+ return `<li class="text-body-1 text-accent">${ content } </li>`
48+ }
49+
50+ renderer . list = function ( { ordered, items } ) {
51+ const tag = ordered ? "ol" : "ul"
52+ const body = items . map ( item => this . listitem ( item ) ) . join ( "" )
53+ return `<${ tag } class="mt-2 mb-4 pl-4" style="list-style-type: square">${ body } </${ tag } >`
54+ }
55+
56+ renderer . link = function ( { href, tokens } ) {
57+ const content = this . parser . parseInline ( tokens )
58+
59+ // if (href.startsWith("/")) {
60+ // const a = document.createElement("a")
61+ // a.href = href
62+ // a.textContent = content
63+ // a.addEventListener("click", (e) => {
64+ // e.preventDefault()
65+ // console.log(e)
66+ // })
67+ // return a.outerHTML
68+ // }
69+
70+ ; ( window as any ) . xonClick = function ( e : Event , _ : HTMLAnchorElement ) {
71+ e . preventDefault ( )
72+ // console.log({ event, target })
73+ }
74+
75+ return `<a class="text-link" href="${ href } " onclick="xonClick(event, this);">${ content } </a>`
76+ }
77+
78+ renderer . codespan = function ( { text } ) {
79+ return `<code
80+ class="text-primary text-body-1 border border-primary py-1 px-2 rounded"
81+ style="background-color: rgba(var(--v-theme-primary), var(--v-border-opacity))"
82+ >${ text } </code>`
83+ }
84+
85+ /* Headings */
86+ // renderer.heading = ({ text, depth: level }) => {
87+ // return `<h${level} class="md-heading text-h${Math.min(level + 3, 6)}">${text}</h${level}>`
88+ // }
89+
90+ /* Paragraphs */
91+ // renderer.paragraph = (text) => {
92+ // return `<p class="md-paragraph">${text}</p>`
93+ // }
94+
95+ /* Links */
96+ // renderer.link = ({ href, title, text }) => {
97+ // const t = title ? ` title="${title}"` : ""
98+ // return `<a class="md-link" href="${href}"${t} target="_blank" rel="noopener noreferrer">${text}</a>`
99+ // }
100+
101+ /* Lists */
102+ // renderer.list = ({ ordered, items }) => {
103+ // const tag = ordered ? "ol" : "ul"
104+ // const body = items.map(item => `<li class="md-list-item">${item}</li>`).join("")
105+ // return `<${tag} class="md-list">${body}</${tag}>`
106+ // }
107+
108+ // renderer.listitem = (text) => {
109+ // return `<li class="md-list-item">${text}</li>`
110+ // }
111+
112+ /* Blockquotes */
113+ // renderer.blockquote = (quote) => {
114+ // return `<blockquote class="md-blockquote">${quote}</blockquote>`
115+ // }
116+
117+ /* Inline code */
118+ // renderer.codespan = (code) => {
119+ // return `<code class="md-inline-code">${code}</code>`
120+ // }
121+
122+ /* Code blocks */
123+ // renderer.code = ({ text, lang }) => {
124+ // const langClass = lang ? ` lang-${lang}` : ""
125+ // return `
126+ // <pre class="md-code-block${langClass}">
127+ // <code class="md-code">${text}</code>
128+ // </pre>
129+ // `
130+ // }
131+
132+ /* Tables */
133+ // renderer.table = ({ header, rows }) => {
134+ // const body = marked.parseInline(rows)
135+ // return `
136+ // <table class="md-table">
137+ // <thead class="md-table-head">${header}</thead>
138+ // <tbody class="md-table-body">${body}</tbody>
139+ // </table>
140+ // `
141+ // }
142+
143+ // renderer.tablerow = (content) => {
144+ // return `<tr class="md-table-row">${content}</tr>`
145+ // }
146+
147+ // renderer.tablecell = (content, flags) => {
148+ // const tag = flags.header ? "th" : "td"
149+ // return `<${tag} class="md-table-cell">${content}</${tag}>`
150+ // }
151+
152+ /* Images */
153+ // renderer.image = ({ href, title, text }) => {
154+ // const t = title ? ` title="${title}"` : ""
155+ // return `<img class="md-image" src="${href}" alt="${text}"${t} />`
156+ // }
157+
158+ /* Horizontal rule */
159+ // renderer.hr = () => {
160+ // return `<hr class="md-hr" />`
161+ // }
162+
163+ /* Strong / emphasis */
164+ // renderer.strong = (text) => {
165+ // return `<strong class="md-strong">${text}</strong>`
166+ // }
167+
168+ // renderer.em = (text) => {
169+ // return `<em class="md-em">${text}</em>`
170+ // }
171+
172+ // function e(name: string, attrs: Record<string, string>) {
173+ // const content = attrs.content ?? ""
174+ // delete attrs.content
175+ // return `<${name} ${Object.entries(attrs).map(([key, value]) => `${key}="${value}"`).join(" ")}>${content}</${name}>`
176+ // }
177+
178+ // marked.use({
179+ // renderer: {
180+ // blockquote({ tokens }) {
181+ // const text = this.parser.parse(tokens)
182+ // return `
183+ // <blockquote
184+ // class="pa-4 border-s-lg border-primary bg-surface"
185+ // style="--v-border-opacity: 1"
186+ // >
187+ // ${text}
188+ // </blockquote>
189+ // `
190+ // },
191+ // code(code) {
192+ // console.log(code)
193+
194+ // if (!code.type) {
195+ // console.log({ code })
196+ // }
197+ // return `
198+ // <pre class="bg-red overflow-y-auto"><code class="language-${code.lang}">${code.text}</code></pre>
199+ // `
200+ // },
201+ // },
202+ // })
35203 return docs . map ( ( doc , index ) => {
36204 const content = contents [ index ] ?? ""
37205 return {
38206 ...doc ,
39207 content,
40208 md : {
41- html : marked . parse ( content ) ,
209+ html : marked . parse ( content , { renderer } ) ,
42210 tableOfContent : [ ] ,
43211 } ,
44212 }
0 commit comments