diff --git a/extend.php b/extend.php
index 07a0a33..47244f1 100644
--- a/extend.php
+++ b/extend.php
@@ -26,6 +26,28 @@
// Overwrite the default inline spoiler so that it is compatible
// with more styling for children in an external stylesheet.
$config->tags['ispoiler']->template = '';
+
+ // Add custom BBCode-style tag for links with target="_blank"
+ // This allows the syntax: [text](url){:target="_blank"}
+ $tag = $config->tags->add('LINK_BLANK');
+ $tag->attributes->add('url')->filterChain->append('#url');
+ $tag->template = '';
+
+ // Add a custom regexp to parse [text](url){:target="_blank"}
+ $config->BBCodes->addCustom(
+ '[text={URL;useContent}]{:target="_blank"}',
+ '{text}'
+ );
+ })
+ ->parse(function ($parser, $context, $text) {
+ // Pre-process text to convert [text](url){:target="_blank"} to BBCode format
+ $text = preg_replace(
+ '/\[([^\]]+)\]\(([^)]+)\)\{:target="_blank"\}/',
+ '[$1=$2]{:target="_blank"}',
+ $text
+ );
+
+ return $text;
}),
new Extend\Locales(__DIR__.'/locale'),
diff --git a/js/src/common/index.js b/js/src/common/index.js
index 6e3bbdf..d3e0fbc 100644
--- a/js/src/common/index.js
+++ b/js/src/common/index.js
@@ -9,7 +9,6 @@
import app from 'flarum/common/app';
import { extend, override } from 'flarum/common/extend';
-import TextEditor from 'flarum/common/components/TextEditor';
import BasicEditorDriver from 'flarum/common/utils/BasicEditorDriver';
import styleSelectedText from 'flarum/common/utils/styleSelectedText';
@@ -27,6 +26,7 @@ const styles = {
quote: { prefix: '> ', multiline: true, surroundWithNewlines: true },
code: { prefix: '`', suffix: '`', blockPrefix: '```', blockSuffix: '```' },
link: { prefix: '[', suffix: '](https://)', replaceNext: 'https://', scanFor: 'https?://' },
+ link_blank: { prefix: '[', suffix: '](https://){:target="_blank"}', replaceNext: 'https://', scanFor: 'https?://' },
image: { prefix: '', replaceNext: 'https://', scanFor: 'https?://' },
unordered_list: { prefix: '- ', multiline: true, surroundWithNewlines: true },
ordered_list: { prefix: '1. ', multiline: true, orderedList: true },
@@ -72,6 +72,7 @@ function markdownToolbarItems(oldFunc) {
items.add('spoiler', , 500);
items.add('code', , 400);
items.add('link', , 300);
+ items.add('link_blank', , 290);
items.add('image', , 200);
items.add(
'unordered_list',
@@ -89,13 +90,9 @@ export function initialize(app) {
items.add('italic', makeShortcut('italic', 'i', this));
});
- if (TextEditor.prototype.markdownToolbarItems) {
- override(TextEditor.prototype, 'markdownToolbarItems', markdownToolbarItems);
- } else {
- TextEditor.prototype.markdownToolbarItems = markdownToolbarItems;
- }
+ override('flarum/common/components/TextEditor', 'markdownToolbarItems', markdownToolbarItems);
- extend(TextEditor.prototype, 'toolbarItems', function (items) {
+ extend('flarum/common/components/TextEditor', 'toolbarItems', function (items) {
items.add(
'markdown',
(shortcutHandler = handler)}>
diff --git a/locale/en.yml b/locale/en.yml
index 30f6783..b5b5d6c 100644
--- a/locale/en.yml
+++ b/locale/en.yml
@@ -7,6 +7,7 @@ flarum-markdown:
image_tooltip: Add an image
italic_tooltip: Add italic text
link_tooltip: Add a link
+ link_blank_tooltip: Add a link (opens in new tab)
ordered_list_tooltip: Add a numbered list
quote_tooltip: Insert a quote
spoiler_tooltip: Insert a spoiler
diff --git a/locale/es.yml b/locale/es.yml
new file mode 100644
index 0000000..2e3e075
--- /dev/null
+++ b/locale/es.yml
@@ -0,0 +1,15 @@
+flarum-markdown:
+ lib:
+ composer:
+ bold_tooltip: Añadir texto en negrita
+ code_tooltip: Insertar código
+ header_tooltip: Agregar texto de encabezado
+ image_tooltip: Añadir una imagen
+ italic_tooltip: Añadir texto en cursiva
+ link_tooltip: Añadir un enlace
+ link_blank_tooltip: Añadir un enlace (se abre en una nueva pestaña)
+ ordered_list_tooltip: Agregar una lista numerada
+ quote_tooltip: Insertar una cita
+ spoiler_tooltip: Insertar un spoiler
+ strikethrough_tooltip: Agregar texto tachado
+ unordered_list_tooltip: Agregar una lista con viñetas