Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ This extension contributes the following settings:
* `wordpress-post.typeAttachedImageSlug` : Processing rules for attached image file names.
* `wordpress-post.mediaTypes` : File extensions and media types to enable.
* `wordpress-post.useLinkableImage` : Add a tag to img tag.
* `wordpress-post.codeBlockLanguagePrefix` : Prefix of class name for code block
* `wordpress-post.codeBlockTag` : HTML tag which specifies language class
* `wordpress-post.debug` : Debug of this extension.

My setting.json is:
Expand Down
18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,24 @@
"default": false,
"description": "Add a tag to img tag"
},
"wordpress-post.codeBlockLanguagePrefix": {
"type": "string",
"default": "language-",
"description": "Prefix of class name for code block"
},
"wordpress-post.codeBlockTag": {
"type": "string",
"default": "code",
"description" : "HTML tag which specifies language class",
"enum" : [
"code",
"pre"
],
"enumDescriptions": [
"Add class for language to <code> tag",
"Add class for language to <pre> tag"
]
},
"wordpress-post.debug": {
"type": "boolean",
"default": false,
Expand Down
16 changes: 16 additions & 0 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,22 @@ export class Context {
return this.getConf("useLinkableImage");
}

/**
* Code Block
*/
getCodeBlockStartTag(lang: string) : string {
const prefix:string = this.getConf("codeBlockLanguagePrefix");
const tag:string = this.getConf("codeBlockTag");
if ( tag === "pre" ) {
return "<pre class=\"" + prefix + lang + "\"><code>";
} else {
return "<pre><code class=\"" + prefix + lang + "\">";
}
}
getCodeBlockEndTag() : string {
return "</code></pre>";
}

getConf(id: string): any {
return vscode.workspace.getConfiguration(this.prefixOfSettings).get(id);
}
Expand Down
8 changes: 6 additions & 2 deletions src/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as vscode from "vscode";
import * as path from "path";
import * as fs from "fs";
import axios from "axios";
import MarkdownIt = require("markdown-it");
import * as matter from "gray-matter";
import * as cheerio from "cheerio";
import { Context } from "./context";
Expand Down Expand Up @@ -71,7 +70,12 @@ export const post = async (context: Context) => {

// markdown -> post data content
context.debug(`[06S] convert to html`);
postData["content"] = MarkdownIt().render(markdown.content);
const md = require('markdown-it')({
highlight: function (str: string, lang: string) {
return context.getCodeBlockStartTag(lang) + md.utils.escapeHtml(str) + context.getCodeBlockEndTag();
}
});
postData["content"] = md.render(markdown.content);
context.debug(`[06E] converted to html`);

// upload attached image file, change src
Expand Down