mirror of
https://github.com/ytliu74/obsidian-pseudocode.git
synced 2026-07-22 07:40:25 +00:00
fix: Cannot export inline macro correctly
This commit is contained in:
parent
743cc7652e
commit
a0ae3321c9
2 changed files with 10 additions and 3 deletions
2
main.ts
2
main.ts
|
|
@ -48,7 +48,7 @@ export default class PseudocodePlugin extends Plugin {
|
|||
|
||||
try {
|
||||
pseudocode.renderElement(preEl, this.settings.jsSettings);
|
||||
createExportButton(this, blockDiv, source);
|
||||
createExportButton(this, blockDiv, inlineMacros, nonMacroLines);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
const errorSpan = blockDiv.createEl("span", {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import PseudocodePlugin from "main";
|
|||
export function createExportButton(
|
||||
parentPlugin: PseudocodePlugin,
|
||||
parentDiv: HTMLDivElement,
|
||||
inlineMacros: string,
|
||||
blockContent: string
|
||||
) {
|
||||
const button = parentDiv.createEl("button");
|
||||
|
|
@ -17,7 +18,7 @@ export function createExportButton(
|
|||
if (blockContent !== null) {
|
||||
const exportContent =
|
||||
"\\documentclass{article}\n" +
|
||||
macros(parentPlugin) +
|
||||
macros(parentPlugin, inlineMacros) +
|
||||
"\n" +
|
||||
"\\begin{document}\n" +
|
||||
processBlock(blockContent, parentPlugin) +
|
||||
|
|
@ -44,10 +45,13 @@ export function createExportButton(
|
|||
});
|
||||
}
|
||||
|
||||
const macros = (parentPlugin: PseudocodePlugin): string => {
|
||||
const macros = (parentPlugin: PseudocodePlugin, inlineMacros: string): string => {
|
||||
const noEnd = parentPlugin.settings.jsSettings.noEnd;
|
||||
const scopeLines = parentPlugin.settings.jsSettings.scopeLines;
|
||||
|
||||
// Split inline macros into lines and remove heading or trailing spaces
|
||||
const inlineMacrosLine = inlineMacros.split("\n").map(line => line.trim());
|
||||
|
||||
return `
|
||||
\\usepackage{algorithm}
|
||||
\\usepackage[noEnd=${noEnd},indLines=${scopeLines}]{algpseudocodex}
|
||||
|
|
@ -64,6 +68,9 @@ const macros = (parentPlugin: PseudocodePlugin): string => {
|
|||
\\renewcommand{\\Output}{\\item[\\textbf{Output:}]}
|
||||
\\newcommand{\\Print}{\\State \\textbf{print~}}
|
||||
\\renewcommand{\\Return}{\\State \\textbf{return~}}
|
||||
|
||||
\\usepackage{amsmath}
|
||||
${inlineMacrosLine}
|
||||
`;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue