mvdkwast / obsidian-copy-as-html

Obsidian plugin: copy document as HTML, including images
MIT License
42 stars 11 forks source link

Plugin fails to remove pinpoints and handle display text of wikilinks #52

Open jonas-sk opened 5 months ago

jonas-sk commented 5 months ago

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:

  1. Add the following text to an editor: [[Test link]]. [[Test link header#header]]. [[Test link block#^test]]. [[Test link display test|display text]]
  2. Activate the "Remove Wikilink brackets" option
  3. Copy with the assigned hotkey for "copy as html"
  4. 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

mvdkwast commented 2 months ago

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 ?

fetwar commented 2 months ago

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

jonas-sk commented 1 month ago

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.

fetwar commented 1 month ago

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

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

Output in reading mode:

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.

fetwar commented 1 month ago

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>
fetwar commented 1 month ago

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 &gt; header</span>.<br>
<span class="internal-link">Test link block &gt; ^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 &gt; header</span>.<br>
<span class="internal-link">Test link block &gt; ^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>