dtext_rb 1.0.10 → 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/ext/dtext/dtext.rl CHANGED
@@ -144,7 +144,9 @@ pixiv_id = 'pixiv #'i digit+ >mark_a1 %mark_a2;
144
144
  pixiv_paged_id = 'pixiv #'i digit+ >mark_a1 %mark_a2 '/p' digit+ >mark_b1 %mark_b2;
145
145
 
146
146
  ws = ' ' | '\t';
147
+ nonperiod = graph - ('.' | '"');
147
148
  header = 'h'i [123456] >mark_a1 %mark_a2 '.' ws*;
149
+ header_with_id = 'h'i [123456] >mark_a1 %mark_a2 '#' nonperiod+ >mark_b1 %mark_b2 '.' ws*;
148
150
  aliased_expand = '[expand='i (nonbracket+ >mark_a1 %mark_a2) ']';
149
151
 
150
152
  list_item = '*'+ >mark_a1 %mark_a2 ws+ nonnewline+ >mark_b1 %mark_b2;
@@ -486,6 +488,12 @@ inline := |*
486
488
  fret;
487
489
  };
488
490
 
491
+ header_with_id => {
492
+ dstack_rewind(sm);
493
+ fexec sm->a1 - 1;
494
+ fret;
495
+ };
496
+
489
497
  '[quote]'i => {
490
498
  g_debug("inline [quote]");
491
499
  dstack_close_before_block(sm);
@@ -796,6 +804,66 @@ list := |*
796
804
  *|;
797
805
 
798
806
  main := |*
807
+ header_with_id => {
808
+ char header = *sm->a1;
809
+ GString * id_name = g_string_new_len(sm->b1, sm->b2 - sm->b1);
810
+
811
+ if (sm->f_inline) {
812
+ header = '6';
813
+ }
814
+
815
+ if (!sm->f_strip) {
816
+ switch (header) {
817
+ case '1':
818
+ dstack_push(sm, &BLOCK_H1);
819
+ append_block(sm, "<h1 id=\"");
820
+ append_block(sm, id_name->str);
821
+ append_block(sm, "\">");
822
+ break;
823
+
824
+ case '2':
825
+ dstack_push(sm, &BLOCK_H2);
826
+ append_block(sm, "<h2 id=\"");
827
+ append_block(sm, id_name->str);
828
+ append_block(sm, "\">");
829
+ break;
830
+
831
+ case '3':
832
+ dstack_push(sm, &BLOCK_H3);
833
+ append_block(sm, "<h3 id=\"");
834
+ append_block(sm, id_name->str);
835
+ append_block(sm, "\">");
836
+ break;
837
+
838
+ case '4':
839
+ dstack_push(sm, &BLOCK_H4);
840
+ append_block(sm, "<h4 id=\"");
841
+ append_block(sm, id_name->str);
842
+ append_block(sm, "\">");
843
+ break;
844
+
845
+ case '5':
846
+ dstack_push(sm, &BLOCK_H5);
847
+ append_block(sm, "<h5 id=\"");
848
+ append_block(sm, id_name->str);
849
+ append_block(sm, "\">");
850
+ break;
851
+
852
+ case '6':
853
+ dstack_push(sm, &BLOCK_H6);
854
+ append_block(sm, "<h6 id=\"");
855
+ append_block(sm, id_name->str);
856
+ append_block(sm, "\">");
857
+ break;
858
+ }
859
+ }
860
+
861
+ sm->header_mode = true;
862
+ g_string_free(id_name, false);
863
+ id_name = NULL;
864
+ fcall inline;
865
+ };
866
+
799
867
  header => {
800
868
  char header = *sm->a1;
801
869
 
data/test/dtext_test.rb CHANGED
@@ -82,6 +82,14 @@ class DTextTest < Minitest::Test
82
82
  assert_parse("<ul><li>a</li></ul><h1>header</h1><ul><li>list</li></ul>", "* a\n\nh1. header\n* list")
83
83
  end
84
84
 
85
+ def test_headers_with_ids
86
+ assert_parse("<h1 id=\"blah-blah\">header</h1>", "h1#blah-blah. header")
87
+ end
88
+
89
+ def test_headers_with_ids_with_quote
90
+ assert_parse("<p>h1#blah-&quot;blah. header</p>", "h1#blah-\"blah. header")
91
+ end
92
+
85
93
  def test_quote_blocks
86
94
  assert_parse('<blockquote><p>test</p></blockquote>', "[quote]\ntest\n[/quote]")
87
95
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dtext_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.10
4
+ version: 1.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - r888888888