From 8c04a9d3900572b54560726bf878ac0a620acb64 Mon Sep 17 00:00:00 2001 From: Type-kun Date: Tue, 6 Sep 2016 01:06:29 +0500 Subject: [PATCH] Fix #2598 for old parser --- app/logical/d_text.rb | 13 +++++++++++-- test/unit/dtext_test.rb | 4 ++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/logical/d_text.rb b/app/logical/d_text.rb index 236a36650..ec165638e 100644 --- a/app/logical/d_text.rb +++ b/app/logical/d_text.rb @@ -193,7 +193,7 @@ class DText str.gsub!(/\[\/code\]\s*/m, "\n\n[/code]\n\n") str.gsub!(/\s*\[spoilers?\](?!\])\s*/m, "\n\n[spoiler]\n\n") str.gsub!(/\s*\[\/spoilers?\]\s*/m, "\n\n[/spoiler]\n\n") - str.gsub!(/^(h[1-6]\.\s*.+)$/, "\n\n\\1\n\n") + str.gsub!(/^(h[1-6](\#[A-z][_A-z0-9-]+)?\.\s*.+)$/, "\n\n\\1\n\n") str.gsub!(/\s*\[expand(\=[^\]]*)?\](?!\])\s*/m, "\n\n[expand\\1]\n\n") str.gsub!(/\s*\[\/expand\]\s*/m, "\n\n[/expand]\n\n") str.gsub!(/\s*\[table\](?!\])\s*/m, "\n\n[table]\n\n") @@ -217,7 +217,16 @@ class DText else "<#{tag}>" + parse_inline(content, options) + "" end - + when /\A(h[1-6])\#([A-z][_A-z0-9-]+)\.\s*(.+)\Z/ + tag = $1 + header_id = $2 + content = $3 + + if options[:inline] + "
" + parse_inline(content, options) + "
" + else + "<#{tag} id=\"#{header_id}\">" + parse_inline(content, options) + "" + end when /^\s*\*+ / parse_list(block, options) diff --git a/test/unit/dtext_test.rb b/test/unit/dtext_test.rb index 5a05b3e02..709672333 100644 --- a/test/unit/dtext_test.rb +++ b/test/unit/dtext_test.rb @@ -75,6 +75,10 @@ class DTextTest < ActiveSupport::TestCase def test_headers assert_equal("

header

", p("h1. header")) end + + def test_headers_with_ids + assert_equal("

header

", p("h1#header-id. header")) + end def test_quote_blocks assert_equal('

test

', p("[quote]\ntest\n[/quote]"))