Fossil

Check-in [0e57bafc]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Improvements to the HTML beautifier.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | wysiwyg
Files: files | file ages | folders
SHA1:0e57bafcfa4d9a9eb19ab63b2ce8ca8ddbd9db39
User & Date: drh 2012-08-11 02:33:17
Context
2012-08-11
13:58
Add <base href="$baseurl/"> to the html header in the default configuration and in all built-in skins. Add a warning if <base> is not configured. Generate hyperlinks from wiki relative to the <base> check-in: 31732d77 user: drh tags: wysiwyg
02:33
Improvements to the HTML beautifier. check-in: 0e57bafc user: drh tags: wysiwyg
2012-08-10
23:18
Reduce the maximum height of a wiki edit frame to 30 rows. check-in: e000f7f0 user: drh tags: wysiwyg
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/wikiformat.c.

1790
1791
1792
1793
1794
1795
1796


1797
1798
1799
1800
1801
1802
1803












1804


1805
1806
1807
1808
1809
1810







1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822







1823
1824
1825












1826
1827





1828
1829
1830





1831
1832
1833
1834
1835
1836
1837
1838

1839
1840

1841
1842
1843
1844
1845
1846
1847
**
** Except, do not do any reformatting inside of <pre>...</pre>
*/
void htmlTidy(const char *zIn, Blob *pOut){
  int n;
  int nPre = 0;
  int iCur = 0;


  while( zIn[0] ){
    n = nextHtmlToken(zIn);
    if( zIn[0]=='<' && n>1 ){
      if( isWord(zIn, "<pre", 4) ){
        if( iCur && nPre==0 ){ blob_append(pOut, "\n", 1); iCur = 0; }
        nPre++;
      }else if( isWord(zIn, "</pre", 5) ){












        nPre--;


        if( nPre==0 ){ blob_append(pOut, "\n", 1); iCur = 0; }
      }else if( isWord(zIn, "<blockquote", 11)
             || isWord(zIn, "<center", 7)
             || (isWord(zIn, "<h", 2) && fossil_isdigit(zIn[2]))
             || isWord(zIn, "<p", 2)
             || isWord(zIn, "<table", 6) ){







        blob_append(pOut, "\n\n", 1 + (iCur>0));
        iCur = 0;
      }else if( isWord(zIn, "<dd", 3)
             || isWord(zIn, "<div", 4)
             || isWord(zIn, "<dl", 3)
             || isWord(zIn, "<dt", 3)
             || isWord(zIn, "<li", 3)
             || isWord(zIn, "<ol", 3)
             || isWord(zIn, "<td", 3)
             || isWord(zIn, "<th", 3)
             || isWord(zIn, "<tr", 3)
             || isWord(zIn, "<ul", 3) ){







        if( iCur>0 ) blob_append(pOut, "\n", 1);
        iCur = 0;
      }












      blob_append(pOut, zIn, n);
      iCur += n;





    }else if( fossil_isspace(zIn[0]) ){
      if( nPre ){
        blob_append(pOut, zIn, n);





      }else if( iCur>=70 ){
        blob_append(pOut, "\n", 1);
        iCur = 0;
      }else{
        blob_append(pOut, " ", 1);
        iCur++;
      }
    }else{

      blob_append(pOut, zIn, n);
      iCur += n;

    }
    zIn += n;
  }
  if( iCur ) blob_append(pOut, "\n", 1);
}

/*







>
>



<
<
|
|
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
|
<
<
<
<
<
>
>
>
>
>
>
>
|
|
<
<
<
<
<
<
<
<
<
<
>
>
>
>
>
>
>
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>


>
>
>
>
>



>
>
>
>
>
|
|
|
|
|
|
|
<
>


>







1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801


1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819





1820
1821
1822
1823
1824
1825
1826
1827
1828










1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872

1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
**
** Except, do not do any reformatting inside of <pre>...</pre>
*/
void htmlTidy(const char *zIn, Blob *pOut){
  int n;
  int nPre = 0;
  int iCur = 0;
  int wantSpace = 0;
  int omitSpace = 1;
  while( zIn[0] ){
    n = nextHtmlToken(zIn);
    if( zIn[0]=='<' && n>1 ){


      int i, j;
      int isCloseTag;
      int eTag;
      int eType;
      char zTag[32];
      isCloseTag = zIn[1]=='/';
      for(i=0, j=1+isCloseTag; i<30 && fossil_isalnum(zIn[j]); i++, j++){
         zTag[i] = fossil_tolower(zIn[j]);
      }
      zTag[i] = 0;
      eTag = findTag(zTag);
      eType = aMarkup[eTag].iType;
      if( eTag==MARKUP_PRE ){
        if( isCloseTag ){
          nPre--;
          blob_append(pOut, zIn, n);
          zIn += n;
          if( nPre==0 ){ blob_append(pOut, "\n", 1); iCur = 0; }





          continue;
        }else{
          if( iCur && nPre==0 ){ blob_append(pOut, "\n", 1); iCur = 0; }
          nPre++;
        }
      }else if( eType & (MUTYPE_BLOCK|MUTYPE_TABLE) ){
        if( !isCloseTag && nPre==0 && blob_size(pOut)>0 ){
          blob_append(pOut, "\n\n", 1 + (iCur>0));
          iCur = 0;










        }
        wantSpace = 0;
        omitSpace = 1;
      }else if( (eType & (MUTYPE_LIST|MUTYPE_LI|MUTYPE_TR|MUTYPE_TD))!=0
             || eTag==MARKUP_HR
      ){
        if( nPre==0 && (!isCloseTag || (eType&MUTYPE_LIST)!=0) && iCur>0 ){
          blob_append(pOut, "\n", 1);
          iCur = 0;
        }
        wantSpace = 0;
        omitSpace = 1;
      }
      if( wantSpace && nPre==0 ){
        if( iCur+n+1>=80 ){
          blob_append(pOut, "\n", 1);
          iCur = 0;
        }else{
          blob_append(pOut, " ", 1);
          iCur++;
        }
      }
      blob_append(pOut, zIn, n);
      iCur += n;
      wantSpace = 0;
      if( eTag==MARKUP_BR || eTag==MARKUP_HR ){
        blob_append(pOut, "\n", 1);
        iCur = 0;
      }
    }else if( fossil_isspace(zIn[0]) ){
      if( nPre ){
        blob_append(pOut, zIn, n);
      }else{
        wantSpace = !omitSpace;
      }
    }else{
      if( wantSpace && nPre==0 ){
        if( iCur+n+1>=80 ){
          blob_append(pOut, "\n", 1);
          iCur = 0;
        }else{
          blob_append(pOut, " ", 1);
          iCur++;
        }

      }
      blob_append(pOut, zIn, n);
      iCur += n;
      wantSpace = omitSpace = 0;
    }
    zIn += n;
  }
  if( iCur ) blob_append(pOut, "\n", 1);
}

/*