diff --git a/src/Markdown.ts b/src/Markdown.ts index 4416872..a1000ee 100644 --- a/src/Markdown.ts +++ b/src/Markdown.ts @@ -9,15 +9,19 @@ let convertor = new Convertor("./src/data/markdown-it-example.md"); let mdoc: string = convertor.process(); -// Configure the client -const api = new GhostAdminAPI({ - url: "http://localhost:2368", - // Admin API key goes here - key: "62ac6f5ab1479d0001082bd4:73341f843a5be78647c6f7e47d43d6cb09ec323df6d5706915df4685b3d46ce7", - version: "v4.0", -}); +let creation = true; -api.posts - .add(JSON.parse(mdoc)) - .then((response: any) => console.log(JSON.stringify(response))) - .catch((error: any) => console.error(error)); +if (creation) { + // Configure the client + const api = new GhostAdminAPI({ + url: "http://localhost:2368", + // Admin API key goes here + key: "62ac6f5ab1479d0001082bd4:73341f843a5be78647c6f7e47d43d6cb09ec323df6d5706915df4685b3d46ce7", + version: "v4.0", + }); + + api.posts + .add(JSON.parse(mdoc)) + .then((response: any) => console.log(JSON.stringify(response))) + .catch((error: any) => console.error(error)); +} diff --git a/src/convertor/Processors.ts b/src/convertor/Processors.ts index ca14051..0bf440f 100644 --- a/src/convertor/Processors.ts +++ b/src/convertor/Processors.ts @@ -14,6 +14,8 @@ const renderer: any = Renderer; const predefinedBlocks = ["blockquote", "table", "bullet_list", "ordered_list"]; +const headerAsMarkdown = true; + export class Convertor { markups: Record = {}; markers: Record = {}; @@ -171,9 +173,24 @@ export class Convertor { private processHeader(stack: Stack[], t: Token): any { console.log("+++++++++++++++++++++++++++++++++++++++++++++"); - console.log(JSON.stringify(t)); + console.log(JSON.stringify(stack[0].token)); - let marker = this.builder.createMarker(t.content, []); - return this.builder.createMarkupSection(stack[0].tag, [marker]); + let result: any = undefined; + + if (!headerAsMarkdown) { + // Build the header as a tag + let marker = this.builder.createMarker(t.content, []); + result = this.builder.createMarkupSection(stack[0].tag, [marker]); + } else { + // build the header as a markdown card + let tbuf: string[] = []; + if (t.map != null) + for (let i = t.map[0]; i < t.map[1]; i++) tbuf.push(this.lines[i]); + result = this.builder.createCardSection("markdown", { + markdown: tbuf.join("\n"), + }); + } + + return result; } }