obsidian-copy-as-html
obsidian-copy-as-html copied to clipboard
Plugin fails to remove pinpoints and handle display text of wikilinks
Describe the bug
The plugin fails to remove the #
and |
portions of a wikilink if the respective option is activated. In addition, one would expect that the display text would be displayed, rather than the link text. (I suspect it also fails to remove the ^
block pinpoint but simply interprets it as superscript.)
To Reproduce Steps to reproduce the behavior:
- Add the following text to an editor:
[[Test link]]. [[Test link header#header]]. [[Test link block#^test]]. [[Test link display test|display text]]
- Activate the "Remove Wikilink brackets" option
- Copy with the assigned hotkey for "copy as html"
- Paste into e.g. Word
Result
Test link. Test link header#header. Test link block#. Test link display test|display text
Expected behavior
Test link. Test link header. Test link block. display text
Hi @jonas-sk, sorry for the late answer.
I think the Obsidian team must have changed how this renders since, because now I get :
Test link.
Test link header > header.
Test link block > ^test.
display text
This looks a lot better. Do you feel that it should be an option to remove the > ...
part also ?
Personally, I think the way it is rendering now is quite nice and more descriptive than just taking the document name itself and throwing away paragraph or block reference info.
I don't have any skin in the matter though so I wouldn't be fussed either way
I think the plugin should use the display text when available and, otherwise, the Obsidian rendering of pinpoints and headers works well, as suggested by @mvdkwast. Doing so, it would follow what we see in the Obsidian read mode.
I think the Obsidian team must have changed how this renders since, because now I get : …
I'm not sure how you get that result, but if I am in edit mode and I invoke the plugin shortcut, the old results still persist.
I agree on that one.
Interesting that we're all getting different results here, I think it may be because of differing Obsidian versions
Testing
- Using "copy document or selection as HTML" command
- Obsidian version v1.5.12
Markdown for testing
[[Test link]].
[[Test link header#header]].
[[Test link block#^test]].
[[Test link display test|display text]]
[[Test link header#header|display text for header]]
[[Test link block#^test|display text for block]]
Output in editing mode
- Same output whether selecting the text or not when executing command:
<div><p><span class="internal-link">Test link</span>.<br>
<span class="internal-link">Test link header > header</span>.<br>
<span class="internal-link">Test link block > ^test</span>.<br>
<span class="internal-link">display text</span><br>
<span class="internal-link">display text for header</span><br>
<span class="internal-link">display text for block</span></p></div>
Output in reading mode:
- Same as editing mode
<div><p><span class="internal-link">Test link</span>.<br>
<span class="internal-link">Test link header > header</span>.<br>
<span class="internal-link">Test link block > ^test</span>.<br>
<span class="internal-link">display text</span><br>
<span class="internal-link">display text for header</span><br>
<span class="internal-link">display text for block</span></p></div>
Both outputs are the same and render like this:
Test link.
Test link header > header.
Test link block > ^test.
display text
display text for header
display text for block
So I am getting the same output as @mvdkwast.
Which version of Obsidian are you running when getting the error @jonas-sk?
I see that in the Obsidian Changelog they have made some changes to the link rendering in the current catalyst preview version - they don't sound like they'll impact the generated previews:
v1.6.0: Added custom instructions and result when adding display text to a link.
I got it to output as described using this markdown:
[[Test link broken block link^test]]
Which gave this HTML output:
<span class="internal-link">Test link broken block link^test</span><br>
but it isn't correctly interpreted by obsidian as a block link anyway, because there is no #
before the ^
. So I don't believe this needs to work within the plugin.
One interesting sidenote is that block definitions aren't included in the HTML output.
e.g.
I am the test content ^test
<div><p>I am the test content </p></div>
I highly doubted it was the command being used, but tried the other two as well.
Copy entire document to clipboard
<div><p><span class="internal-link">Test link</span>.<br>
<span class="internal-link">Test link header > header</span>.<br>
<span class="internal-link">Test link block > ^test</span>.<br>
<span class="internal-link">display text</span><br>
<span class="internal-link">display text for header</span><br>
<span class="internal-link">display text for block</span></p></div>
Copy current selection to clipboard
<div><p><span class="internal-link">Test link</span>.<br>
<span class="internal-link">Test link header > header</span>.<br>
<span class="internal-link">Test link block > ^test</span>.<br>
<span class="internal-link">display text</span><br>
<span class="internal-link">display text for header</span><br>
<span class="internal-link">display text for block</span></p></div>
@jonas-sk, do you still have this problem with the latest version of Obsidian ? If so, feel free to reopen this issue !