OSDN Git Service

wiki paragraph gap feature.
authorvisor <visor@users.sourceforge.jp>
Thu, 9 Jun 2016 15:17:55 +0000 (00:17 +0900)
committervisor <visor@users.sourceforge.jp>
Thu, 9 Jun 2016 15:17:55 +0000 (00:17 +0900)
wiki/wikiformat.cc
wiki/wikiformat.h

index fd3ec90..eddd786 100644 (file)
@@ -133,6 +133,8 @@ void  WikiBlockComplex::outputBlock (MotorOutput* out) {
  
  空行は,段落を分ける。
 
+ 段落と段落の間に空行を2行以上入れると、「<div class="pggap"></div>」を出力する。
+
 */
 bool  WikiBlockParagraph::nextLine (uiterator b, uiterator e) {
     if (*b == kWikiP) {
@@ -1534,6 +1536,49 @@ void  WikiBlockRaw::output (MotorOutput* out) {
 }
 
 /* ============================================================ */
+bool  WikiBlockBlank::nextLine (uiterator b, uiterator e) {
+    if (b == e) {
+       count ++;
+       return true;
+    } else {
+       switch (*b) {           // paragraph以外の全て
+       case kWikiH:
+       case kWikiPRE:
+       case kWikiPRE2:
+       case kWikiUL:
+       case kWikiOL:
+       case kWikiNL:
+       case kWikiDL:
+       case kWikiTABLE:
+           count = 0;
+           break;
+       default:
+           if ((*b == kWikiQUOTE && e - b == 1) ||
+               matchHead (b, e, CharConst (uWikiDIV)) ||
+               (wiki->curform == NULL && matchHead (b, e, CharConst (uWikiFORM))) ||
+               (wiki->curform == NULL && matchHead (b, e, CharConst (uWikiELEMENT))) ||
+               matchHead (b, e, CharConst ("----"))) {
+               count = 0;
+           } else {
+               if (count >= 2)
+                   enable = true;
+           }
+       }
+       return false;
+    }
+}
+
+void  WikiBlockBlank::addLine (uiterator b, uiterator e) {
+    count ++;
+}
+
+void  WikiBlockBlank::output (MotorOutput* out) {
+    if (enable) {
+       out->out_raw (CharConst ("<div class=\"pggap\"></div>\n"));
+    }
+}
+
+/* ============================================================ */
 void  WikiFormat::pass1 (const ustring& text, WikiLine::linevec* block, bool fsuper) {
     SplitterNL  sp (text);
 
@@ -1808,17 +1853,28 @@ void  WikiFormat::compileLine (WikiLineScanner& scanner) {
     WikiLine*  wl = scanner.cur ();
     if (! wl)
        return;
-
-    uiterator  b = wl->begin;
-    uiterator  e = wl->end;
-
     if (wl->fn) {
        wl->fn (wl, this);
     } else {
+       uiterator  b = wl->begin;
+       uiterator  e = wl->end;
+
        if (b == e) {           // empty line
            if (cur) {
-               cur->close ();
-               cur = NULL;
+               switch (cur->type) {
+               case WikiBlock::BlockParagraph:
+                   cur->close ();
+                   cur = new WikiBlockBlank (this);
+                   blockp->push_back (cur);
+                   cur->addLine (b, e);
+                   break;
+               case WikiBlock::BlockBlank:
+                   cur->addLine (b, e);
+                   break;
+               default:
+                   cur->close ();
+                   cur = NULL;
+               }
            }
        } else if (matchSkip (b, e, CharConst ("//"))) {        // comment
        } else if (checkClose (b, e)) {
index 505546d..d40ec28 100644 (file)
@@ -161,6 +161,7 @@ class  WikiBlock {
        BlockElement,
        BlockHR,
        BlockRaw,
+       BlockBlank,
     }  blockType;
     typedef enum {
        CloseNA,
@@ -518,6 +519,26 @@ class  WikiBlockRaw: public WikiBlock {
     virtual void  output (MotorOutput* out);
 };
 
+class  WikiBlockBlank: public WikiBlock {
+ public:
+    int  count;
+    bool  enable;
+
+    WikiBlockBlank (WikiFormat* w): WikiBlock (BlockBlank, w) {
+       count = 0;
+       enable = false;
+    };
+    virtual  ~WikiBlockBlank () {};
+
+    virtual bool  nextLine (uiterator b, uiterator e);
+    virtual void  addLine (uiterator b, uiterator e);
+    virtual void  output (MotorOutput* out);
+};
+inline WikiBlockBlank*  WikiBlockBlank_type (WikiBlock* b) {
+    assert (b->type == WikiBlock::BlockBlank);
+    return (WikiBlockBlank*)b;
+}
+
 class  WikiFormat {
  public:
     typedef  enum {