Skip to content

Commit

Permalink
fix: metabind input view
Browse files Browse the repository at this point in the history
  • Loading branch information
Mara-Li committed Jul 16, 2024
1 parent 4f24f4e commit 8a9b645
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/utils/pluginFix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,18 @@ export function removeDataBasePluginRelationShip(): string {
return getSelection.toString();
}
}

/**
* Metabind is rendered like this, in the HTML:
* ```html
* <code class="mb-view mb-view-inline"><div class="mb-view-wrapper mb-view-text mb-view-type-math">xxx</div></code>
* ```
* This return a strange formated code block in markdown, this function fix it, with converting to <code>text</code>
* @param html
*/
export function fixMetaBindCopy(html: string) {
return html.replace(
/<code class="mb-view mb-view-inline"><div class="mb-view-wrapper mb-view-text mb-view-type-math">(.+?)<\/div><\/code>/g,
"<code>$1</code>"
);
}
5 changes: 4 additions & 1 deletion src/utils/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { type App, type Editor, type EditorPosition, htmlToMarkdown } from "obsi
import { COLLAPSE_INDICATOR, type GlobalSettings } from "../interface";
import type EnhancedCopy from "../main";
import { reNumerateList, replaceAllDivCalloutToBlockquote } from "./node_edit";
import { fixMetaBindCopy } from "./pluginFix";

/**
* Get the selection of the activeWindows and transform it as HTML
Expand Down Expand Up @@ -31,7 +32,9 @@ export function getSelectionAsHTML(settings: GlobalSettings): string {
return div.innerHTML;
}
const allNoConvert = div.querySelectorAll("[data-type='html']");
let markdown = htmlToMarkdown(div.innerHTML.replace(COLLAPSE_INDICATOR, ""));
let markdown = htmlToMarkdown(
fixMetaBindCopy(div.innerHTML.replace(COLLAPSE_INDICATOR, ""))
);
//no converting html to markdown the div that contains a class with "no-convert"
for (const noConvert of allNoConvert) {
const converted = htmlToMarkdown(noConvert.outerHTML);
Expand Down

0 comments on commit 8a9b645

Please sign in to comment.