webtrees icon indicating copy to clipboard operation
webtrees copied to clipboard

Changes to enable markdown in ResearchTask (_TODO) entry

Open elysch opened this issue 6 months ago • 1 comments

Hello.

I hope this helps others. I needed to add a link in a ResearchTask (_TODO) entry so I made this change in order to acomplish that.

I can't create a Pull Request now.

In resources/view/fact.phtml

Here, where it says the following :

                <div class="wt-fact-value">
                    <?= $element->value($value, $tree) ?>

Change it to:

                <div class="wt-fact-value">
                    <?php if (($tag == '_TODO') && ($tree->getPreference('FORMAT_TEXT') === 'markdown')) :
                              $valueTmp = Registry::markdownFactory()->markdown($element->value($value, $tree));
                              $valueTmp = strtr($valueTmp, [MarkdownFactory::BREAK => ' ']);
                              $valueTmp = htmlspecialchars_decode($valueTmp, ENT_QUOTES);
                              echo $valueTmp;
                          else :
                    ?>
                        <?= $element->value($value, $tree) ?>
                    <?php endif ?>

elysch avatar May 24 '25 00:05 elysch

A little bug fix. The references were not being replaced by links, since a $tree parameter was missing in the markdown function call:

                <div class="wt-fact-value">
                    <?php if (($tag == '_TODO') && ($tree->getPreference('FORMAT_TEXT') === 'markdown')) :
                              $valueTmp = Registry::markdownFactory()->markdown($element->value($value, $tree), $tree);
                              $valueTmp = strtr($valueTmp, [MarkdownFactory::BREAK => ' ']);
                              $valueTmp = htmlspecialchars_decode($valueTmp, ENT_QUOTES);
                              echo $valueTmp;
                          else :
                    ?>
                        <?= $element->value($value, $tree) ?>
                    <?php endif ?>

elysch avatar May 25 '25 02:05 elysch

A simpler way to acheive this is to change the type of the _TODO element from a simple value to the same formatted-text value used by NOTE and TEXT.

However, this doesn't affect the home-page block. This will show the raw content of the element, without converting links and formatting. That's a little more complicated.

fisharebest avatar Oct 31 '25 12:10 fisharebest