Skip to content

Commit

Permalink
Merge pull request #128 from khusmann/md_header_style
Browse files Browse the repository at this point in the history
Md header style
  • Loading branch information
telesoho authored Nov 5, 2023
2 parents b252053 + 337f720 commit fac37c1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@
"default": true,
"description": "Enable/disable converting html to markdown."
},
"MarkdownPaste.headerStyle": {
"type": "string",
"scope": "resource",
"enum": [
"setext",
"atx"
],
"default": "setext",
"description": "Use setext or atx style markdown headers."
},
"MarkdownPaste.enableRulesForHtml": {
"type": "boolean",
"scope": "resource",
Expand Down
3 changes: 2 additions & 1 deletion src/paster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,15 @@ class Paster {

let enableHtmlConverter = Paster.getConfig().enableHtmlConverter;
let enableRulesForHtml = Paster.getConfig().enableRulesForHtml;
let headerStyle = Paster.getConfig().headerStyle;

Logger.log("Clipboard Type:", ctx_type);
switch (ctx_type) {
case xclip.ClipboardType.Html:
if (enableHtmlConverter) {
const html = await cb.getTextHtml();
Logger.log(html);
const markdown = toMarkdown(html);
const markdown = toMarkdown(html, headerStyle);
if (enableRulesForHtml) {
let newMarkdown = Paster.parse(markdown);
Paster.writeToEditor(newMarkdown);
Expand Down
4 changes: 2 additions & 2 deletions src/toMarkdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function cell(content, node) {
return prefix + content + " " + suffix;
}

function toMarkdown(content) {
function toMarkdown(content, headingStyle) {
// http://pandoc.org/README.html#pandocs-markdown
const pandoc = [
// {
Expand Down Expand Up @@ -254,7 +254,7 @@ function toMarkdown(content) {
};

var TurndownService = require("turndown");
var turndownService = new TurndownService();
var turndownService = new TurndownService({ headingStyle });
Object.entries(pandoc).forEach(([key, value]) => {
turndownService.addRule(key, value);
});
Expand Down

0 comments on commit fac37c1

Please sign in to comment.