Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Markdown text is always transcluded in block mode #8917

Open
yaisog opened this issue Jan 28, 2025 · 1 comment
Open

[BUG] Markdown text is always transcluded in block mode #8917

yaisog opened this issue Jan 28, 2025 · 1 comment

Comments

@yaisog
Copy link
Contributor

yaisog commented Jan 28, 2025

Describe the bug

When I use $transclude with $type="text/markdown", it will always be transcluded in block mode, even when setting $mode="inline" explicitly.

Expected behavior

$transclude should respect its context, especially when set explicity, even with Markdown type.

To Reproduce

  1. Go to the markdowndemo site.
  2. Create this tiddler with any title:
tags: $:/tags/Global

\define some-text() *markdown italic*
  1. Create this tiddler with any other title:
type: text/markdown

<$transclude $variable="some-text" /> will be transcluded as inline TiddlyText when not explicitly declaring a type.

Let's transclude <$transclude $variable="some-text" $type="text/markdown" $mode="inline" /> with explicit type `text/markdown`.

Screenshots

No response

TiddlyWiki Configuration

TiddlyWiki 5.3.6

Additional context

The transcluded content is always wrapped in

<div class="markdown">
  <p>
    transcluded text
  </p>
</div>
@yaisog yaisog changed the title [BUG] MarkDown text is always transcluded in block mode [BUG] Markdown text is always transcluded in block mode Jan 31, 2025
@yaisog
Copy link
Contributor Author

yaisog commented Jan 31, 2025

I did some digging and found that the parser ignores the parseAsInline option.

When changing these lines in $:/plugins/tiddlywiki/markdown/wrapper.js

var mdTree = md.parse(text,env);
var textToParse = '<div class="markdown">\n' + md.renderer.render(mdTree,md.options,env) + '</div>';

to

var mdTree, textToParse;
if (options.parseAsInline === true) {
	mdTree = md.parseInline(text, env);
	textToParse = '<span class="markdown-inline">\n' + md.renderer.render(mdTree,md.options,env) + '</span>';
} else {
	mdTree = md.parse(text, env);
	textToParse = '<div class="markdown">\n' + md.renderer.render(mdTree,md.options,env) + '</div>';
}

it works as expected, though I did not do a thorough check for side effects. As long as parseAsInline is not true, the behavior should be identical to before.
Since there is a display: block; rule for the markdown class, I chose a different class name for inline content.

Tagging @cdruan, as he's been implementing the plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant