Export markdown without extra line breaks #628
-
Thanks again for your work on this plugin, which is amazing. I have noticed that when I try to export Zotero notes that are in outline format, a couple of things sometimes go wrong with the formatting in the exported markdown note: (1) most importantly, the outlines have extra line breaks built in, so that the outline looks very drawn out and is hard to read (see screenshot, with Zotero and Obsidian notes side-by-side); and (2) sometimes the bold formatting extends throughout an entire outline entry rather than stopping with the words that were originally bolded (also in screenshot). Might it be possible to fix these things? (And sorry for the second issue post so soon! I've been sitting on this one while trying to resolve the other.) |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments
-
The empty line is a writing style, as it does not affect the markdown rendering. it's not a bug so there is no need to I cannot reproduce the bold bug. Could you please check where the bold mark |
Beta Was this translation helpful? Give feedback.
-
I guess I'm not sure what a writing style is. Do you just mean that the empty lines are added deliberately because some people prefer them? Is there any way for an individual user to prevent the extra line breaks so that the outline in the markdown looks like the outline in the Zotero note? I don't really want to change this in every markdown note but, even if I tried to, the changes I think are overridden by Zotero anytime I manually sync. If there's no way to do this currently, then I would request that as a feature. I think a lot of people take notes in outline form and prefer that the markdown outline looks just like the original Zotero outline. I think the bold is occurring when I accidentally highlight a space right after the targeted word in Zotero--which in the markdown applies the bold attribute to everything after the space, too. So that's just something that I can be more careful of on my own and probably doesn't require a fix. Thanks so much for your quick reply! |
Beta Was this translation helpful? Give feedback.
-
I encountered another spacing format issue, actually. When I force-synced the note I had shown before, additional spaces appear around a word that was italicized. The extra line breaks/spaces were not there originally in Zotero, but were added upon a forced "sync now" with Obsidian. I have seen this before, but couldn't find an example. I don't think that this would just be considered writing style. See attached. |
Beta Was this translation helpful? Give feedback.
-
In the beta release 1.1.4-9, a new template type You can add anything you want to parse the content/change the markdown style with JS script. For example, you can simply remove the empty lines between item lists by importing the template share code below: # This template is specifically for importing/sharing, using better
# notes 'import from clipboard': copy the content and
# goto Zotero menu bar, click Edit->New Template from Clipboard.
# Do not copy-paste this to better notes template editor directly.
name: "[ExportMDFileContent]"
content: |-
${{
let lines = mdContent.split("\n");
function isItemListLine(line) {
return line.trim().startsWith("* ");
}
let filteredLines = [];
for (let i = 0; i < lines.length; i++) {
let currentLine = lines[i];
if (i > 0 && i < lines.length - 1) {
// Not first or last line. Check empty lines between item list lines
let previousLine = lines[i-1];
let nextLine = lines[i+1];
if (isItemListLine(previousLine)
&& isItemListLine(nextLine)
&& currentLine.trim().length === 0) {
// Skip empty line
continue;
}
}
filteredLines.push(currentLine);
}
return filteredLines.join("\n");
}}$
|
Beta Was this translation helpful? Give feedback.
-
Wow, this is fabulous. Thank you for introducing it. I hadn't been using the beta but just now switched over. The template works beautifully for ordinary bulleted lists. But it doesn't seem to work for me for numbered lists or for nested lists (see first two screenshots below, with Zotero note to the left of the Better Notes markdown render). Is there something that I could add to the script that you provided to account for those cases, too? The export process also seems to--only when I include a quote in a list--always add an extra line on either side of the citation, so that the citation gets broken apart from the actual quote (see final screenshot). Could you perhaps tell me which element I should be looking for to change here to prevent the extra lines? Thanks again for your help. |
Beta Was this translation helpful? Give feedback.
-
The line break is an allowed syntax of markdown - the problem here is just obsidian does not render it correctly (I guess, because my vscode ignores these empty lines when rendering) The template share code that removes empty lines between both numbered/bullet lists: # This template is specifically for importing/sharing, using better
# notes 'import from clipboard': copy the content and
# goto Zotero menu bar, click Edit->New Template from Clipboard.
# Do not copy-paste this to better notes template editor directly.
name: "[ExportMDFileContent]"
content: |-
${{
let lines = mdContent.split("\n");
function isListLine(line) {
return /^(?:\*|-|\+|[0-9]+\.)(?= )/.test(line.trim());
}
let filteredLines = [];
for (let i = 0; i < lines.length; i++) {
let currentLine = lines[i];
if (i > 0 && i < lines.length - 1) {
// Not first or last line. Check empty lines between item list lines
let previousLine = lines[i-1];
let nextLine = lines[i+1];
if (isListLine(previousLine)
&& isListLine(nextLine)
&& currentLine.trim().length === 0) {
// Skip empty line
continue;
}
}
filteredLines.push(currentLine);
}
return filteredLines.join("\n");
}}$ |
Beta Was this translation helpful? Give feedback.
-
That works. Thanks a million! |
Beta Was this translation helpful? Give feedback.
-
This thread might be helpful to others and I will convert it to discussions |
Beta Was this translation helpful? Give feedback.
The line break is an allowed syntax of markdown - the problem here is just obsidian does not render it correctly (I guess, because my vscode ignores these empty lines when rendering)
The template share code that removes empty lines between both numbered/bullet lists: