mirror of
https://github.com/ytliu74/obsidian-pseudocode.git
synced 2026-07-22 07:40:25 +00:00
feat: Custom settings available for export
This commit is contained in:
parent
0e09e52568
commit
2aa4bae01b
2 changed files with 43 additions and 19 deletions
2
main.ts
2
main.ts
|
|
@ -43,7 +43,7 @@ export default class PseudocodePlugin extends Plugin {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
pseudocode.renderElement(preEl, this.settings.jsSettings);
|
pseudocode.renderElement(preEl, this.settings.jsSettings);
|
||||||
createExportButton(blockDiv, source);
|
createExportButton(this, blockDiv, source);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
const errorSpan = blockDiv.createEl("span", {
|
const errorSpan = blockDiv.createEl("span", {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,10 @@ const BUTTON_INFO = "Export to clipboard";
|
||||||
const BUTTON_EXPORTED = "Exported!";
|
const BUTTON_EXPORTED = "Exported!";
|
||||||
const BUTTON_FAILED = "Failed to export";
|
const BUTTON_FAILED = "Failed to export";
|
||||||
|
|
||||||
|
import PseudocodePlugin from "main";
|
||||||
|
|
||||||
export function createExportButton(
|
export function createExportButton(
|
||||||
|
parentPlugin: PseudocodePlugin,
|
||||||
parentDiv: HTMLDivElement,
|
parentDiv: HTMLDivElement,
|
||||||
blockContent: string
|
blockContent: string
|
||||||
) {
|
) {
|
||||||
|
|
@ -14,10 +17,10 @@ export function createExportButton(
|
||||||
if (blockContent !== null) {
|
if (blockContent !== null) {
|
||||||
const exportContent =
|
const exportContent =
|
||||||
"\\documentclass{article}\n" +
|
"\\documentclass{article}\n" +
|
||||||
MACROS +
|
macros(parentPlugin) +
|
||||||
"\n" +
|
"\n" +
|
||||||
"\\begin{document}\n" +
|
"\\begin{document}\n" +
|
||||||
blockContent +
|
processBlock(blockContent, parentPlugin) +
|
||||||
"\n\\end{document}";
|
"\n\\end{document}";
|
||||||
|
|
||||||
navigator.clipboard
|
navigator.clipboard
|
||||||
|
|
@ -41,19 +44,40 @@ export function createExportButton(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const MACROS =
|
const macros = (parentPlugin: PseudocodePlugin): string => {
|
||||||
"\\usepackage{algorithm}\n" +
|
const noEnd = parentPlugin.settings.jsSettings.noEnd;
|
||||||
"\\usepackage{algpseudocode}\n" +
|
const scopeLines = parentPlugin.settings.jsSettings.scopeLines;
|
||||||
"\n" +
|
|
||||||
"\\newcommand{\\And}{\\textbf{and~}}\n" +
|
return `
|
||||||
"\\newcommand{\\Or}{\\textbf{or~}}\n" +
|
\\usepackage{algorithm}
|
||||||
"\\newcommand{\\Xor}{\\textbf{xor~}}\n" +
|
\\usepackage[noEnd=${noEnd},indLines=${scopeLines}]{algpseudocodex}
|
||||||
"\\newcommand{\\Not}{\\textbf{not~}}\n" +
|
|
||||||
"\\newcommand{\\To}{\\textbf{to~}}\n" +
|
\\newcommand{\\And}{\\textbf{and~}}
|
||||||
"\\newcommand{\\DownTo}{\\textbf{downto~}}\n" +
|
\\newcommand{\\Or}{\\textbf{or~}}
|
||||||
"\\newcommand{\\True}{\\textbf{true~}}\n" +
|
\\newcommand{\\Xor}{\\textbf{xor~}}
|
||||||
"\\newcommand{\\False}{\\textbf{false~}}\n" +
|
\\newcommand{\\Not}{\\textbf{not~}}
|
||||||
"\\newcommand{\\Input}{\\item[\\textbf{Input:}]}\n" +
|
\\newcommand{\\To}{\\textbf{to~}}
|
||||||
"\\newcommand{\\Output}{\\item[\\textbf{Output:}]}\n" +
|
\\newcommand{\\DownTo}{\\textbf{downto~}}
|
||||||
"\\renewcommand{\\Return}{\\State \\textbf{return~}}\n" +
|
\\newcommand{\\True}{\\textbf{true~}}
|
||||||
"\\newcommand{\\Print}{\\State \\textbf{print~}}\n";
|
\\newcommand{\\False}{\\textbf{false~}}
|
||||||
|
\\newcommand{\\Input}{\\item[\\textbf{Input:}]}
|
||||||
|
\\renewcommand{\\Output}{\\item[\\textbf{Output:}]}
|
||||||
|
\\newcommand{\\Print}{\\State \\textbf{print~}}
|
||||||
|
\\renewcommand{\\Return}{\\State \\textbf{return~}}
|
||||||
|
`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const processBlock = (
|
||||||
|
block: string,
|
||||||
|
parentPlugin: PseudocodePlugin
|
||||||
|
): string => {
|
||||||
|
if (parentPlugin.settings.jsSettings.lineNumber)
|
||||||
|
// Replace "\begin{algorithmic}" with "\begin{algorithmic}[1]"
|
||||||
|
block = block.replace(
|
||||||
|
"\\begin{algorithmic}",
|
||||||
|
"\\begin{algorithmic}[1]"
|
||||||
|
);
|
||||||
|
else;
|
||||||
|
|
||||||
|
return block;
|
||||||
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue