converte url text to markdown link in a automatic way #654

Open
opened 2026-02-04 21:36:26 +03:00 by OVERLORD · 3 comments
Owner

Originally created by @junlicn on GitHub (Apr 25, 2018).

For Feature Requests

Desired Feature:
I most markdown editor, when I paste a http link, usually it will auto convert into a in fact link in preview page. but in bookstack's markdown editor, I need to add xxx to make the link.

my desire feature is add a text : https://www.example.com will auto generate a preview link I could click.

For Bug Reports

  • BookStack Version (Found in settings, Please don't put 'latest'):
  • PHP Version:
  • MySQL Version:
Expected Behavior
Current Behavior
Steps to Reproduce
Originally created by @junlicn on GitHub (Apr 25, 2018). ### For Feature Requests Desired Feature: I most markdown editor, when I paste a http link, usually it will auto convert into a in fact link in preview page. but in bookstack's markdown editor, I need to add [xxx](link) to make the link. my desire feature is add a text : https://www.example.com will auto generate a preview link I could click. ### For Bug Reports * BookStack Version *(Found in settings, Please don't put 'latest')*: * PHP Version: * MySQL Version: ##### Expected Behavior ##### Current Behavior ##### Steps to Reproduce
OVERLORD added the 🛠️ Enhancement label 2026-02-04 21:36:26 +03:00
Author
Owner

@prohtex commented on GitHub (Jun 19, 2025):

I'd love this too. @ssddanbrown any chance we could enable this CommonMark extension?

use League\CommonMark\Extension\Autolink\AutolinkExtension;
use League\CommonMark\Environment\Environment;

$environment = new Environment([]);
$environment->addExtension(new AutolinkExtension());

It is trivial to do with a JS injection but I'm concerned about page load performance. I'd also like to a Blade hack that wouldn't survive upgrades.

@prohtex commented on GitHub (Jun 19, 2025): I'd love this too. @ssddanbrown any chance we could enable this CommonMark extension? ``` use League\CommonMark\Extension\Autolink\AutolinkExtension; use League\CommonMark\Environment\Environment; $environment = new Environment([]); $environment->addExtension(new AutolinkExtension()); ``` It is trivial to do with a JS injection but I'm concerned about page load performance. I'd also like to a Blade hack that wouldn't survive upgrades.
Author
Owner

@ssddanbrown commented on GitHub (Jun 19, 2025):

@prohtex I'm not keen on adding auto-conversion by default (and changing default behaviour) but we allow customization of the Commonmark environment via the logical theme system. Relevant event:

e65b4b63a2/app/Theming/ThemeEvents.php (L80-L88)

Therefore, you could use that to add this to an existing BookStack instance as-is.

@ssddanbrown commented on GitHub (Jun 19, 2025): @prohtex I'm not keen on adding auto-conversion by default (and changing default behaviour) but we allow customization of the Commonmark environment via the [logical theme system](https://github.com/BookStackApp/BookStack/blob/development/dev/docs/logical-theme-system.md). Relevant event: https://github.com/BookStackApp/BookStack/blob/e65b4b63a2ba2bda2104e46c9053453c51ce2331/app/Theming/ThemeEvents.php#L80-L88 Therefore, you could use that to add this to an existing BookStack instance as-is.
Author
Owner

@prohtex commented on GitHub (Jun 24, 2025):

@prohtex I'm not keen on adding auto-conversion by default (and changing default behaviour) but we allow customization of the Commonmark environment via the logical theme system. Relevant event:

BookStack/app/Theming/ThemeEvents.php

Lines 80 to 88 in e65b4b6

 /** 
  * Commonmark environment configure. 
  * Provides the commonmark library environment for customization before it's used to render markdown content. 
  * If the listener returns a non-null value, that will be used as an environment instead. 
  * 
  * @param \League\CommonMark\Environment\Environment $environment 
  * @returns \League\CommonMark\Environment\Environment|null 
  */ 
 const COMMONMARK_ENVIRONMENT_CONFIGURE = 'commonmark_environment_configure'; 

Therefore, you could use that to add this to an existing BookStack instance as-is.

Thanks @ssddanbrown. For the curious I got this working by creating a theme and overriding the functions.php file (also with a carriage-return tweak):

<?php

use BookStack\Theming\ThemeEvents;
use BookStack\Facades\Theme;
use League\CommonMark\Extension\Autolink\AutolinkExtension;

Theme::listen(ThemeEvents::COMMONMARK_ENVIRONMENT_CONFIGURE, function ($environment) {
    // Add autolink support
    $environment->addExtension(new AutolinkExtension());

    // Preserve existing soft_break config
    $environment->mergeConfig([
        'renderer' => [
            'soft_break' => "<br>\n",
        ],
    ]);

    return $environment;
});

Then you need this in your header:

<!-- This is needed to replicate line break behavior in markdown editor preview -->
<script>
  window.addEventListener('editor-markdown::setup', event => {
    event.detail.markdownIt.set({
      breaks: true,
      linkify: true
    });
  });
</script>
@prohtex commented on GitHub (Jun 24, 2025): > [@prohtex](https://github.com/prohtex) I'm not keen on adding auto-conversion by default (and changing default behaviour) but we allow customization of the Commonmark environment via the [logical theme system](https://github.com/BookStackApp/BookStack/blob/development/dev/docs/logical-theme-system.md). Relevant event: > > [BookStack/app/Theming/ThemeEvents.php](https://github.com/BookStackApp/BookStack/blob/e65b4b63a2ba2bda2104e46c9053453c51ce2331/app/Theming/ThemeEvents.php#L80-L88) > > Lines 80 to 88 in [e65b4b6](/BookStackApp/BookStack/commit/e65b4b63a2ba2bda2104e46c9053453c51ce2331) > > /** > * Commonmark environment configure. > * Provides the commonmark library environment for customization before it's used to render markdown content. > * If the listener returns a non-null value, that will be used as an environment instead. > * > * @param \League\CommonMark\Environment\Environment $environment > * @returns \League\CommonMark\Environment\Environment|null > */ > const COMMONMARK_ENVIRONMENT_CONFIGURE = 'commonmark_environment_configure'; > Therefore, you could use that to add this to an existing BookStack instance as-is. Thanks @ssddanbrown. For the curious I got this working by creating a theme and overriding the functions.php file (also with a carriage-return tweak): ``` <?php use BookStack\Theming\ThemeEvents; use BookStack\Facades\Theme; use League\CommonMark\Extension\Autolink\AutolinkExtension; Theme::listen(ThemeEvents::COMMONMARK_ENVIRONMENT_CONFIGURE, function ($environment) { // Add autolink support $environment->addExtension(new AutolinkExtension()); // Preserve existing soft_break config $environment->mergeConfig([ 'renderer' => [ 'soft_break' => "<br>\n", ], ]); return $environment; }); ``` Then you need this in your header: ``` <!-- This is needed to replicate line break behavior in markdown editor preview --> <script> window.addEventListener('editor-markdown::setup', event => { event.detail.markdownIt.set({ breaks: true, linkify: true }); }); </script> ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#654