breakout_parser 0.0.17 → 0.0.18
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/ChangeLog +6 -0
- data/README +28 -0
- data/ext/breakout_parser/parser.tab.c +141 -125
- data/ext/breakout_parser/parser.tab.h +7 -8
- data/ext/breakout_parser/parser.y +10 -1
- data/ext/breakout_parser/ruby_ext.c +8 -3
- data/spec/parser_spec.rb +37 -5
- metadata +14 -4
data/ChangeLog
CHANGED
data/README
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
Breakout Parser
|
2
|
+
===============
|
3
|
+
|
4
|
+
- simplified Textile parser with some Assembla-specific features
|
5
|
+
- converts Textile into HTML
|
6
|
+
|
7
|
+
|
8
|
+
Usage
|
9
|
+
===============
|
10
|
+
|
11
|
+
require 'breakout_parser'
|
12
|
+
puts BreakoutParser.parse("h1. xxx", "my_space")
|
13
|
+
# prints: <h1 id="h-xxx">xxx</h1>
|
14
|
+
|
15
|
+
puts BreakoutParser.parse_links_only("h1. http://xxx", "my_space")
|
16
|
+
# prints: h1. <a rel="nofollow" href="http://xxx">http://xxx</a>
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
Arguments
|
21
|
+
===============
|
22
|
+
|
23
|
+
BreakoutParser.parse(
|
24
|
+
data, # data to parse
|
25
|
+
space_name, # space name - for links parsing
|
26
|
+
site_url, # [optional] global site url
|
27
|
+
git_url # [optional] custom GIT url - f.ex. for github-hosted repos
|
28
|
+
)
|
@@ -1,10 +1,9 @@
|
|
1
|
-
|
2
|
-
/* A Bison parser, made by GNU Bison 2.4.1. */
|
1
|
+
/* A Bison parser, made by GNU Bison 2.4.2. */
|
3
2
|
|
4
3
|
/* Skeleton implementation for Bison's Yacc-like parsers in C
|
5
4
|
|
6
|
-
Copyright (C) 1984, 1989
|
7
|
-
|
5
|
+
Copyright (C) 1984, 1989-1990, 2000-2006, 2009-2010 Free Software
|
6
|
+
Foundation, Inc.
|
8
7
|
|
9
8
|
This program is free software: you can redistribute it and/or modify
|
10
9
|
it under the terms of the GNU General Public License as published by
|
@@ -46,7 +45,7 @@
|
|
46
45
|
#define YYBISON 1
|
47
46
|
|
48
47
|
/* Bison version. */
|
49
|
-
#define YYBISON_VERSION "2.4.
|
48
|
+
#define YYBISON_VERSION "2.4.2"
|
50
49
|
|
51
50
|
/* Skeleton name. */
|
52
51
|
#define YYSKELETON_NAME "yacc.c"
|
@@ -68,7 +67,7 @@
|
|
68
67
|
/* Copy the first part of user declarations. */
|
69
68
|
|
70
69
|
/* Line 189 of yacc.c */
|
71
|
-
#line
|
70
|
+
#line 2 "parser.y"
|
72
71
|
|
73
72
|
#include <stdio.h>
|
74
73
|
#include <stdlib.h>
|
@@ -97,6 +96,7 @@ size_t site_url_len = 0;
|
|
97
96
|
extern VALUE git_url;
|
98
97
|
|
99
98
|
int list_level = 1;
|
99
|
+
int absolute_urls = 0;
|
100
100
|
|
101
101
|
#define CHECK_BUF_SIZE(len) \
|
102
102
|
if( (bufptr - buf + len + 1) >= bufsize ){ \
|
@@ -217,7 +217,7 @@ typedef union YYSTYPE
|
|
217
217
|
{
|
218
218
|
|
219
219
|
/* Line 214 of yacc.c */
|
220
|
-
#line
|
220
|
+
#line 70 "parser.y"
|
221
221
|
|
222
222
|
double dvalue;
|
223
223
|
int ivalue;
|
@@ -288,7 +288,7 @@ typedef short int yytype_int16;
|
|
288
288
|
#define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
|
289
289
|
|
290
290
|
#ifndef YY_
|
291
|
-
# if YYENABLE_NLS
|
291
|
+
# if defined YYENABLE_NLS && YYENABLE_NLS
|
292
292
|
# if ENABLE_NLS
|
293
293
|
# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
|
294
294
|
# define YY_(msgid) dgettext ("bison-runtime", msgid)
|
@@ -546,14 +546,14 @@ static const yytype_int8 yyrhs[] =
|
|
546
546
|
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
|
547
547
|
static const yytype_uint8 yyrline[] =
|
548
548
|
{
|
549
|
-
0,
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
549
|
+
0, 98, 98, 99, 102, 103, 104, 105, 106, 107,
|
550
|
+
108, 109, 112, 109, 116, 119, 116, 123, 125, 126,
|
551
|
+
128, 129, 131, 132, 134, 135, 137, 138, 140, 141,
|
552
|
+
142, 143, 144, 145, 146, 147, 148, 149, 150, 151,
|
553
|
+
152, 153, 155, 156, 157, 158, 159, 160, 161, 162,
|
554
|
+
163, 164, 165, 167, 168, 170, 177, 178, 179, 180,
|
555
|
+
181, 183, 184, 185, 188, 188, 189, 190, 190, 191,
|
556
|
+
191
|
557
557
|
};
|
558
558
|
#endif
|
559
559
|
|
@@ -733,9 +733,18 @@ static const yytype_uint8 yystos[] =
|
|
733
733
|
|
734
734
|
/* Like YYERROR except do call yyerror. This remains here temporarily
|
735
735
|
to ease the transition to the new meaning of YYERROR, for GCC.
|
736
|
-
Once GCC version 2 has supplanted version 1, this can go.
|
736
|
+
Once GCC version 2 has supplanted version 1, this can go. However,
|
737
|
+
YYFAIL appears to be in use. Nevertheless, it is formally deprecated
|
738
|
+
in Bison 2.4.2's NEWS entry, where a plan to phase it out is
|
739
|
+
discussed. */
|
737
740
|
|
738
741
|
#define YYFAIL goto yyerrlab
|
742
|
+
#if defined YYFAIL
|
743
|
+
/* This is here to suppress warnings from the GCC cpp's
|
744
|
+
-Wunused-macros. Normally we don't worry about that warning, but
|
745
|
+
some users do, and we want to make it easy for users to remove
|
746
|
+
YYFAIL uses, which will produce warnings from Bison 2.5. */
|
747
|
+
#endif
|
739
748
|
|
740
749
|
#define YYRECOVERING() (!!yyerrstatus)
|
741
750
|
|
@@ -792,7 +801,7 @@ while (YYID (0))
|
|
792
801
|
we won't break user code: when these are the locations we know. */
|
793
802
|
|
794
803
|
#ifndef YY_LOCATION_PRINT
|
795
|
-
# if YYLTYPE_IS_TRIVIAL
|
804
|
+
# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
|
796
805
|
# define YY_LOCATION_PRINT(File, Loc) \
|
797
806
|
fprintf (File, "%d.%d-%d.%d", \
|
798
807
|
(Loc).first_line, (Loc).first_column, \
|
@@ -1531,43 +1540,43 @@ yyreduce:
|
|
1531
1540
|
{
|
1532
1541
|
case 6:
|
1533
1542
|
|
1534
|
-
/* Line
|
1535
|
-
#line
|
1543
|
+
/* Line 1464 of yacc.c */
|
1544
|
+
#line 104 "parser.y"
|
1536
1545
|
{concat("</h1>",5);}
|
1537
1546
|
break;
|
1538
1547
|
|
1539
1548
|
case 7:
|
1540
1549
|
|
1541
|
-
/* Line
|
1542
|
-
#line
|
1550
|
+
/* Line 1464 of yacc.c */
|
1551
|
+
#line 105 "parser.y"
|
1543
1552
|
{concat("</h2>",5);}
|
1544
1553
|
break;
|
1545
1554
|
|
1546
1555
|
case 8:
|
1547
1556
|
|
1548
|
-
/* Line
|
1549
|
-
#line
|
1557
|
+
/* Line 1464 of yacc.c */
|
1558
|
+
#line 106 "parser.y"
|
1550
1559
|
{concat("</h3>",5);}
|
1551
1560
|
break;
|
1552
1561
|
|
1553
1562
|
case 9:
|
1554
1563
|
|
1555
|
-
/* Line
|
1556
|
-
#line
|
1564
|
+
/* Line 1464 of yacc.c */
|
1565
|
+
#line 107 "parser.y"
|
1557
1566
|
{concat("</h4>",5);}
|
1558
1567
|
break;
|
1559
1568
|
|
1560
1569
|
case 10:
|
1561
1570
|
|
1562
|
-
/* Line
|
1563
|
-
#line
|
1571
|
+
/* Line 1464 of yacc.c */
|
1572
|
+
#line 108 "parser.y"
|
1564
1573
|
{concat("</h5>",5);}
|
1565
1574
|
break;
|
1566
1575
|
|
1567
1576
|
case 11:
|
1568
1577
|
|
1569
|
-
/* Line
|
1570
|
-
#line
|
1578
|
+
/* Line 1464 of yacc.c */
|
1579
|
+
#line 109 "parser.y"
|
1571
1580
|
{
|
1572
1581
|
list_level=1;
|
1573
1582
|
concat("<ul>",4)
|
@@ -1576,8 +1585,8 @@ yyreduce:
|
|
1576
1585
|
|
1577
1586
|
case 12:
|
1578
1587
|
|
1579
|
-
/* Line
|
1580
|
-
#line
|
1588
|
+
/* Line 1464 of yacc.c */
|
1589
|
+
#line 112 "parser.y"
|
1581
1590
|
{
|
1582
1591
|
concat("</ul>",5);
|
1583
1592
|
for(; list_level>1 && list_level<4; list_level--) concat("</li></ul>",10);
|
@@ -1586,8 +1595,8 @@ yyreduce:
|
|
1586
1595
|
|
1587
1596
|
case 14:
|
1588
1597
|
|
1589
|
-
/* Line
|
1590
|
-
#line
|
1598
|
+
/* Line 1464 of yacc.c */
|
1599
|
+
#line 116 "parser.y"
|
1591
1600
|
{
|
1592
1601
|
list_level=1;
|
1593
1602
|
concat("<ol>",4)
|
@@ -1596,8 +1605,8 @@ yyreduce:
|
|
1596
1605
|
|
1597
1606
|
case 15:
|
1598
1607
|
|
1599
|
-
/* Line
|
1600
|
-
#line
|
1608
|
+
/* Line 1464 of yacc.c */
|
1609
|
+
#line 119 "parser.y"
|
1601
1610
|
{
|
1602
1611
|
concat("</ol>",5);
|
1603
1612
|
for(; list_level>1 && list_level<4; list_level--) concat("</li></ol>",10);
|
@@ -1606,302 +1615,302 @@ yyreduce:
|
|
1606
1615
|
|
1607
1616
|
case 18:
|
1608
1617
|
|
1609
|
-
/* Line
|
1610
|
-
#line
|
1618
|
+
/* Line 1464 of yacc.c */
|
1619
|
+
#line 125 "parser.y"
|
1611
1620
|
{concat("</li>",5);}
|
1612
1621
|
break;
|
1613
1622
|
|
1614
1623
|
case 19:
|
1615
1624
|
|
1616
|
-
/* Line
|
1617
|
-
#line
|
1625
|
+
/* Line 1464 of yacc.c */
|
1626
|
+
#line 126 "parser.y"
|
1618
1627
|
{concat("</li>",5);}
|
1619
1628
|
break;
|
1620
1629
|
|
1621
1630
|
case 22:
|
1622
1631
|
|
1623
|
-
/* Line
|
1624
|
-
#line
|
1632
|
+
/* Line 1464 of yacc.c */
|
1633
|
+
#line 131 "parser.y"
|
1625
1634
|
{concat("</li>",5);}
|
1626
1635
|
break;
|
1627
1636
|
|
1628
1637
|
case 23:
|
1629
1638
|
|
1630
|
-
/* Line
|
1631
|
-
#line
|
1639
|
+
/* Line 1464 of yacc.c */
|
1640
|
+
#line 132 "parser.y"
|
1632
1641
|
{concat("</li>",5);}
|
1633
1642
|
break;
|
1634
1643
|
|
1635
1644
|
case 30:
|
1636
1645
|
|
1637
|
-
/* Line
|
1638
|
-
#line
|
1646
|
+
/* Line 1464 of yacc.c */
|
1647
|
+
#line 142 "parser.y"
|
1639
1648
|
{concat2((yyvsp[(1) - (1)].svalue));}
|
1640
1649
|
break;
|
1641
1650
|
|
1642
1651
|
case 31:
|
1643
1652
|
|
1644
|
-
/* Line
|
1645
|
-
#line
|
1653
|
+
/* Line 1464 of yacc.c */
|
1654
|
+
#line 143 "parser.y"
|
1646
1655
|
{process_url((yyvsp[(1) - (1)].svalue));}
|
1647
1656
|
break;
|
1648
1657
|
|
1649
1658
|
case 32:
|
1650
1659
|
|
1651
|
-
/* Line
|
1652
|
-
#line
|
1660
|
+
/* Line 1464 of yacc.c */
|
1661
|
+
#line 144 "parser.y"
|
1653
1662
|
{process_email((yyvsp[(1) - (1)].svalue));}
|
1654
1663
|
break;
|
1655
1664
|
|
1656
1665
|
case 33:
|
1657
1666
|
|
1658
|
-
/* Line
|
1659
|
-
#line
|
1667
|
+
/* Line 1464 of yacc.c */
|
1668
|
+
#line 145 "parser.y"
|
1660
1669
|
{(yyvsp[(1) - (1)].ivalue) ? concat(" <strong>",9) : concat("<strong>",8);}
|
1661
1670
|
break;
|
1662
1671
|
|
1663
1672
|
case 34:
|
1664
1673
|
|
1665
|
-
/* Line
|
1666
|
-
#line
|
1674
|
+
/* Line 1464 of yacc.c */
|
1675
|
+
#line 146 "parser.y"
|
1667
1676
|
{concat("</strong>",9);}
|
1668
1677
|
break;
|
1669
1678
|
|
1670
1679
|
case 35:
|
1671
1680
|
|
1672
|
-
/* Line
|
1673
|
-
#line
|
1681
|
+
/* Line 1464 of yacc.c */
|
1682
|
+
#line 147 "parser.y"
|
1674
1683
|
{(yyvsp[(1) - (1)].ivalue) ? concat(" <em>",5) : concat("<em>",4);}
|
1675
1684
|
break;
|
1676
1685
|
|
1677
1686
|
case 36:
|
1678
1687
|
|
1679
|
-
/* Line
|
1680
|
-
#line
|
1688
|
+
/* Line 1464 of yacc.c */
|
1689
|
+
#line 148 "parser.y"
|
1681
1690
|
{concat("</em>",5);}
|
1682
1691
|
break;
|
1683
1692
|
|
1684
1693
|
case 37:
|
1685
1694
|
|
1686
|
-
/* Line
|
1687
|
-
#line
|
1695
|
+
/* Line 1464 of yacc.c */
|
1696
|
+
#line 149 "parser.y"
|
1688
1697
|
{(yyvsp[(1) - (1)].ivalue) ? concat(" <strong><em>",13) : concat("<strong><em>",12);}
|
1689
1698
|
break;
|
1690
1699
|
|
1691
1700
|
case 38:
|
1692
1701
|
|
1693
|
-
/* Line
|
1694
|
-
#line
|
1702
|
+
/* Line 1464 of yacc.c */
|
1703
|
+
#line 150 "parser.y"
|
1695
1704
|
{(yyvsp[(1) - (1)].ivalue) ? concat(" <em><strong>",13) : concat("<em><strong>",12);}
|
1696
1705
|
break;
|
1697
1706
|
|
1698
1707
|
case 39:
|
1699
1708
|
|
1700
|
-
/* Line
|
1701
|
-
#line
|
1709
|
+
/* Line 1464 of yacc.c */
|
1710
|
+
#line 151 "parser.y"
|
1702
1711
|
{process_inline_code((yyvsp[(1) - (1)].svalue));}
|
1703
1712
|
break;
|
1704
1713
|
|
1705
1714
|
case 40:
|
1706
1715
|
|
1707
|
-
/* Line
|
1708
|
-
#line
|
1716
|
+
/* Line 1464 of yacc.c */
|
1717
|
+
#line 152 "parser.y"
|
1709
1718
|
{revert_bold();}
|
1710
1719
|
break;
|
1711
1720
|
|
1712
1721
|
case 41:
|
1713
1722
|
|
1714
|
-
/* Line
|
1715
|
-
#line
|
1723
|
+
/* Line 1464 of yacc.c */
|
1724
|
+
#line 153 "parser.y"
|
1716
1725
|
{revert_italic();}
|
1717
1726
|
break;
|
1718
1727
|
|
1719
1728
|
case 42:
|
1720
1729
|
|
1721
|
-
/* Line
|
1722
|
-
#line
|
1730
|
+
/* Line 1464 of yacc.c */
|
1731
|
+
#line 155 "parser.y"
|
1723
1732
|
{process_ticket_link((yyvsp[(1) - (1)].svalue));}
|
1724
1733
|
break;
|
1725
1734
|
|
1726
1735
|
case 43:
|
1727
1736
|
|
1728
|
-
/* Line
|
1729
|
-
#line
|
1737
|
+
/* Line 1464 of yacc.c */
|
1738
|
+
#line 156 "parser.y"
|
1730
1739
|
{process_svn_link((yyvsp[(1) - (1)].svalue),0);}
|
1731
1740
|
break;
|
1732
1741
|
|
1733
1742
|
case 44:
|
1734
1743
|
|
1735
|
-
/* Line
|
1736
|
-
#line
|
1744
|
+
/* Line 1464 of yacc.c */
|
1745
|
+
#line 157 "parser.y"
|
1737
1746
|
{process_git_link((yyvsp[(1) - (1)].svalue),0);}
|
1738
1747
|
break;
|
1739
1748
|
|
1740
1749
|
case 45:
|
1741
1750
|
|
1742
|
-
/* Line
|
1743
|
-
#line
|
1751
|
+
/* Line 1464 of yacc.c */
|
1752
|
+
#line 158 "parser.y"
|
1744
1753
|
{process_svn_link((yyvsp[(1) - (1)].svalue),1);}
|
1745
1754
|
break;
|
1746
1755
|
|
1747
1756
|
case 46:
|
1748
1757
|
|
1749
|
-
/* Line
|
1750
|
-
#line
|
1758
|
+
/* Line 1464 of yacc.c */
|
1759
|
+
#line 159 "parser.y"
|
1751
1760
|
{process_git_link((yyvsp[(1) - (1)].svalue),1);}
|
1752
1761
|
break;
|
1753
1762
|
|
1754
1763
|
case 47:
|
1755
1764
|
|
1756
|
-
/* Line
|
1757
|
-
#line
|
1765
|
+
/* Line 1464 of yacc.c */
|
1766
|
+
#line 160 "parser.y"
|
1758
1767
|
{process_url_link((yyvsp[(1) - (1)].svalue),NULL);}
|
1759
1768
|
break;
|
1760
1769
|
|
1761
1770
|
case 48:
|
1762
1771
|
|
1763
|
-
/* Line
|
1764
|
-
#line
|
1772
|
+
/* Line 1464 of yacc.c */
|
1773
|
+
#line 161 "parser.y"
|
1765
1774
|
{process_url_link((yyvsp[(1) - (1)].svalue),"http://");}
|
1766
1775
|
break;
|
1767
1776
|
|
1768
1777
|
case 49:
|
1769
1778
|
|
1770
|
-
/* Line
|
1771
|
-
#line
|
1779
|
+
/* Line 1464 of yacc.c */
|
1780
|
+
#line 162 "parser.y"
|
1772
1781
|
{process_wiki_link((yyvsp[(1) - (1)].svalue));}
|
1773
1782
|
break;
|
1774
1783
|
|
1775
1784
|
case 50:
|
1776
1785
|
|
1777
|
-
/* Line
|
1778
|
-
#line
|
1786
|
+
/* Line 1464 of yacc.c */
|
1787
|
+
#line 163 "parser.y"
|
1779
1788
|
{process_anchor_link((yyvsp[(1) - (1)].svalue));}
|
1780
1789
|
break;
|
1781
1790
|
|
1782
1791
|
case 51:
|
1783
1792
|
|
1784
|
-
/* Line
|
1785
|
-
#line
|
1793
|
+
/* Line 1464 of yacc.c */
|
1794
|
+
#line 164 "parser.y"
|
1786
1795
|
{process_file_link((yyvsp[(1) - (1)].svalue));}
|
1787
1796
|
break;
|
1788
1797
|
|
1789
1798
|
case 52:
|
1790
1799
|
|
1791
|
-
/* Line
|
1792
|
-
#line
|
1800
|
+
/* Line 1464 of yacc.c */
|
1801
|
+
#line 165 "parser.y"
|
1793
1802
|
{process_image_link((yyvsp[(1) - (1)].svalue));}
|
1794
1803
|
break;
|
1795
1804
|
|
1796
1805
|
case 55:
|
1797
1806
|
|
1798
|
-
/* Line
|
1799
|
-
#line
|
1807
|
+
/* Line 1464 of yacc.c */
|
1808
|
+
#line 170 "parser.y"
|
1800
1809
|
{concat_escaped_char((yyvsp[(1) - (1)].ivalue));}
|
1801
1810
|
break;
|
1802
1811
|
|
1803
1812
|
case 56:
|
1804
1813
|
|
1805
|
-
/* Line
|
1806
|
-
#line
|
1814
|
+
/* Line 1464 of yacc.c */
|
1815
|
+
#line 177 "parser.y"
|
1807
1816
|
{concat("<h1 id=\"h-",10); process_header((yyvsp[(1) - (1)].svalue));}
|
1808
1817
|
break;
|
1809
1818
|
|
1810
1819
|
case 57:
|
1811
1820
|
|
1812
|
-
/* Line
|
1813
|
-
#line
|
1821
|
+
/* Line 1464 of yacc.c */
|
1822
|
+
#line 178 "parser.y"
|
1814
1823
|
{concat("<h2 id=\"h-",10); process_header((yyvsp[(1) - (1)].svalue));}
|
1815
1824
|
break;
|
1816
1825
|
|
1817
1826
|
case 58:
|
1818
1827
|
|
1819
|
-
/* Line
|
1820
|
-
#line
|
1828
|
+
/* Line 1464 of yacc.c */
|
1829
|
+
#line 179 "parser.y"
|
1821
1830
|
{concat("<h3 id=\"h-",10); process_header((yyvsp[(1) - (1)].svalue));}
|
1822
1831
|
break;
|
1823
1832
|
|
1824
1833
|
case 59:
|
1825
1834
|
|
1826
|
-
/* Line
|
1827
|
-
#line
|
1835
|
+
/* Line 1464 of yacc.c */
|
1836
|
+
#line 180 "parser.y"
|
1828
1837
|
{concat("<h4 id=\"h-",10); process_header((yyvsp[(1) - (1)].svalue));}
|
1829
1838
|
break;
|
1830
1839
|
|
1831
1840
|
case 60:
|
1832
1841
|
|
1833
|
-
/* Line
|
1834
|
-
#line
|
1842
|
+
/* Line 1464 of yacc.c */
|
1843
|
+
#line 181 "parser.y"
|
1835
1844
|
{concat("<h5 id=\"h-",10); process_header((yyvsp[(1) - (1)].svalue));}
|
1836
1845
|
break;
|
1837
1846
|
|
1838
1847
|
case 61:
|
1839
1848
|
|
1840
|
-
/* Line
|
1841
|
-
#line
|
1849
|
+
/* Line 1464 of yacc.c */
|
1850
|
+
#line 183 "parser.y"
|
1842
1851
|
{process_oli((yyvsp[(1) - (1)].ivalue));}
|
1843
1852
|
break;
|
1844
1853
|
|
1845
1854
|
case 62:
|
1846
1855
|
|
1847
|
-
/* Line
|
1848
|
-
#line
|
1856
|
+
/* Line 1464 of yacc.c */
|
1857
|
+
#line 184 "parser.y"
|
1849
1858
|
{process_uli((yyvsp[(1) - (1)].ivalue));}
|
1850
1859
|
break;
|
1851
1860
|
|
1852
1861
|
case 63:
|
1853
1862
|
|
1854
|
-
/* Line
|
1855
|
-
#line
|
1863
|
+
/* Line 1464 of yacc.c */
|
1864
|
+
#line 185 "parser.y"
|
1856
1865
|
{concat("<br />",6);}
|
1857
1866
|
break;
|
1858
1867
|
|
1859
1868
|
case 64:
|
1860
1869
|
|
1861
|
-
/* Line
|
1862
|
-
#line
|
1870
|
+
/* Line 1464 of yacc.c */
|
1871
|
+
#line 188 "parser.y"
|
1863
1872
|
{concat("<pre><code>",11);}
|
1864
1873
|
break;
|
1865
1874
|
|
1866
1875
|
case 65:
|
1867
1876
|
|
1868
|
-
/* Line
|
1869
|
-
#line
|
1877
|
+
/* Line 1464 of yacc.c */
|
1878
|
+
#line 188 "parser.y"
|
1870
1879
|
{concat("</code></pre>",13);}
|
1871
1880
|
break;
|
1872
1881
|
|
1873
1882
|
case 67:
|
1874
1883
|
|
1875
|
-
/* Line
|
1876
|
-
#line
|
1884
|
+
/* Line 1464 of yacc.c */
|
1885
|
+
#line 190 "parser.y"
|
1877
1886
|
{concat("<pre>",5);}
|
1878
1887
|
break;
|
1879
1888
|
|
1880
1889
|
case 68:
|
1881
1890
|
|
1882
|
-
/* Line
|
1883
|
-
#line
|
1891
|
+
/* Line 1464 of yacc.c */
|
1892
|
+
#line 190 "parser.y"
|
1884
1893
|
{concat("</pre>",6);}
|
1885
1894
|
break;
|
1886
1895
|
|
1887
1896
|
case 69:
|
1888
1897
|
|
1889
|
-
/* Line
|
1890
|
-
#line
|
1898
|
+
/* Line 1464 of yacc.c */
|
1899
|
+
#line 191 "parser.y"
|
1891
1900
|
{concat("<code>",6);}
|
1892
1901
|
break;
|
1893
1902
|
|
1894
1903
|
case 70:
|
1895
1904
|
|
1896
|
-
/* Line
|
1897
|
-
#line
|
1905
|
+
/* Line 1464 of yacc.c */
|
1906
|
+
#line 191 "parser.y"
|
1898
1907
|
{concat("</code>",7);}
|
1899
1908
|
break;
|
1900
1909
|
|
1901
1910
|
|
1902
1911
|
|
1903
|
-
/* Line
|
1904
|
-
#line
|
1912
|
+
/* Line 1464 of yacc.c */
|
1913
|
+
#line 1914 "parser.tab.c"
|
1905
1914
|
default: break;
|
1906
1915
|
}
|
1907
1916
|
YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
|
@@ -2112,8 +2121,8 @@ yyreturn:
|
|
2112
2121
|
|
2113
2122
|
|
2114
2123
|
|
2115
|
-
/* Line
|
2116
|
-
#line
|
2124
|
+
/* Line 1684 of yacc.c */
|
2125
|
+
#line 195 "parser.y"
|
2117
2126
|
|
2118
2127
|
|
2119
2128
|
process_uli(int level){
|
@@ -2258,7 +2267,14 @@ process_anchor_link(const char*target){
|
|
2258
2267
|
process_url_link(const char*target,const char* proto){
|
2259
2268
|
const char *c;
|
2260
2269
|
concat("<a rel=\"nofollow\" href=\"",24);
|
2261
|
-
if(proto)
|
2270
|
+
if(proto){
|
2271
|
+
concat2(proto);
|
2272
|
+
} else if(target && *target == '/'){
|
2273
|
+
// relative link
|
2274
|
+
if( absolute_urls && site_url ){
|
2275
|
+
concat2(site_url);
|
2276
|
+
}
|
2277
|
+
}
|
2262
2278
|
for(c=target; *c && *c != ']' && *c != '|'; c++) concat_raw_char(*c);
|
2263
2279
|
process_link_tail(target,NULL,proto);
|
2264
2280
|
}
|
@@ -1,10 +1,9 @@
|
|
1
|
-
|
2
|
-
/* A Bison parser, made by GNU Bison 2.4.1. */
|
1
|
+
/* A Bison parser, made by GNU Bison 2.4.2. */
|
3
2
|
|
4
3
|
/* Skeleton interface for Bison's Yacc-like parsers in C
|
5
4
|
|
6
|
-
Copyright (C) 1984, 1989
|
7
|
-
|
5
|
+
Copyright (C) 1984, 1989-1990, 2000-2006, 2009-2010 Free Software
|
6
|
+
Foundation, Inc.
|
8
7
|
|
9
8
|
This program is free software: you can redistribute it and/or modify
|
10
9
|
it under the terms of the GNU General Public License as published by
|
@@ -91,8 +90,8 @@
|
|
91
90
|
typedef union YYSTYPE
|
92
91
|
{
|
93
92
|
|
94
|
-
/* Line
|
95
|
-
#line
|
93
|
+
/* Line 1685 of yacc.c */
|
94
|
+
#line 70 "parser.y"
|
96
95
|
|
97
96
|
double dvalue;
|
98
97
|
int ivalue;
|
@@ -100,8 +99,8 @@ typedef union YYSTYPE
|
|
100
99
|
|
101
100
|
|
102
101
|
|
103
|
-
/* Line
|
104
|
-
#line
|
102
|
+
/* Line 1685 of yacc.c */
|
103
|
+
#line 104 "parser.tab.h"
|
105
104
|
} YYSTYPE;
|
106
105
|
# define YYSTYPE_IS_TRIVIAL 1
|
107
106
|
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
|
@@ -1,3 +1,4 @@
|
|
1
|
+
// vim:ts=4:sw=4:expandtab
|
1
2
|
%{
|
2
3
|
#include <stdio.h>
|
3
4
|
#include <stdlib.h>
|
@@ -26,6 +27,7 @@ size_t site_url_len = 0;
|
|
26
27
|
extern VALUE git_url;
|
27
28
|
|
28
29
|
int list_level = 1;
|
30
|
+
int absolute_urls = 0;
|
29
31
|
|
30
32
|
#define CHECK_BUF_SIZE(len) \
|
31
33
|
if( (bufptr - buf + len + 1) >= bufsize ){ \
|
@@ -334,7 +336,14 @@ process_anchor_link(const char*target){
|
|
334
336
|
process_url_link(const char*target,const char* proto){
|
335
337
|
const char *c;
|
336
338
|
concat("<a rel=\"nofollow\" href=\"",24);
|
337
|
-
if(proto)
|
339
|
+
if(proto){
|
340
|
+
concat2(proto);
|
341
|
+
} else if(target && *target == '/'){
|
342
|
+
// relative link
|
343
|
+
if( absolute_urls && site_url ){
|
344
|
+
concat2(site_url);
|
345
|
+
}
|
346
|
+
}
|
338
347
|
for(c=target; *c && *c != ']' && *c != '|'; c++) concat_raw_char(*c);
|
339
348
|
process_link_tail(target,NULL,proto);
|
340
349
|
}
|
@@ -24,14 +24,14 @@ extern size_t site_url_len;
|
|
24
24
|
|
25
25
|
VALUE git_url;
|
26
26
|
|
27
|
-
extern int parse_links_only;
|
27
|
+
extern int parse_links_only, absolute_urls;
|
28
28
|
|
29
29
|
VALUE do_parse(int argc, VALUE *argv, VALUE self) {
|
30
30
|
VALUE s, text, r_space_name;
|
31
31
|
char *p;
|
32
32
|
|
33
|
-
if( argc < 2 || argc >
|
34
|
-
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2..
|
33
|
+
if( argc < 2 || argc > 5 ){
|
34
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2..5)", argc);
|
35
35
|
return rb_str_new("",0); // unreachable code, but for double safety
|
36
36
|
}
|
37
37
|
|
@@ -53,6 +53,11 @@ VALUE do_parse(int argc, VALUE *argv, VALUE self) {
|
|
53
53
|
git_url = argv[3];
|
54
54
|
}
|
55
55
|
|
56
|
+
absolute_urls = 0;
|
57
|
+
if( argc > 4 && argv[4] != Qnil && argv[4] != Qfalse ){
|
58
|
+
absolute_urls = 1;
|
59
|
+
}
|
60
|
+
|
56
61
|
if(!text || text == Qnil || text == Qfalse){
|
57
62
|
// NULL input string
|
58
63
|
return rb_str_new("",0);
|
data/spec/parser_spec.rb
CHANGED
@@ -24,13 +24,13 @@ describe 'BreakoutParser' do
|
|
24
24
|
r
|
25
25
|
end
|
26
26
|
|
27
|
-
it 'accepts from 2 to
|
28
|
-
[0,1,
|
27
|
+
it 'accepts from 2 to 5 arguments' do
|
28
|
+
[0,1,6,7,8,9,10].each do |argc|
|
29
29
|
lambda{
|
30
30
|
BreakoutParser.parse(*(['a']*argc))
|
31
|
-
}.should raise_error(ArgumentError, "wrong number of arguments (#{argc} for 2..
|
31
|
+
}.should raise_error(ArgumentError, "wrong number of arguments (#{argc} for 2..5)")
|
32
32
|
end
|
33
|
-
(2..
|
33
|
+
(2..5).each do |argc|
|
34
34
|
lambda{
|
35
35
|
BreakoutParser.parse(*(['a']*argc))
|
36
36
|
}.should_not raise_error
|
@@ -924,6 +924,33 @@ describe 'BreakoutParser' do
|
|
924
924
|
}.should_not raise_error
|
925
925
|
end
|
926
926
|
|
927
|
+
describe "absolute_urls" do
|
928
|
+
# 'true' values
|
929
|
+
[true, 1, 'x'].each do |v|
|
930
|
+
it "should NOT convert relative url to absolute when absolute_urls = #{v.inspect} AND site_url is NULL" do
|
931
|
+
parse("[[url:/rel]]", :absolute_urls => v).should ==
|
932
|
+
'<a rel="nofollow" href="/rel">/rel</a>'
|
933
|
+
parse("[[url:/rel|text]]", :absolute_urls => v).should ==
|
934
|
+
'<a rel="nofollow" href="/rel">text</a>'
|
935
|
+
end
|
936
|
+
it "should convert relative url to absolute when absolute_urls = #{v.inspect}" do
|
937
|
+
parse("[[url:/rel]]", :absolute_urls => v, :site_url => 'http://www.ru').should ==
|
938
|
+
'<a rel="nofollow" href="http://www.ru/rel">/rel</a>'
|
939
|
+
parse("[[url:/rel|text]]", :absolute_urls => v, :site_url => 'http://www.ru').should ==
|
940
|
+
'<a rel="nofollow" href="http://www.ru/rel">text</a>'
|
941
|
+
end
|
942
|
+
end
|
943
|
+
# 'false' values
|
944
|
+
[false, nil].each do |v|
|
945
|
+
it "should not convert relative url to absolute when absolute_urls = #{v.inspect}" do
|
946
|
+
parse("[[url:/rel]]", :absolute_urls => v).should ==
|
947
|
+
'<a rel="nofollow" href="/rel">/rel</a>'
|
948
|
+
parse("[[url:/rel|text]]", :absolute_urls => v).should ==
|
949
|
+
'<a rel="nofollow" href="/rel">text</a>'
|
950
|
+
end
|
951
|
+
end
|
952
|
+
end
|
953
|
+
|
927
954
|
a = {}
|
928
955
|
a["image:ExistingImage.png"] =
|
929
956
|
'<img src="/spaces/test_space/documents/download/ExistingImage.png" alt="ALT" />'
|
@@ -982,6 +1009,11 @@ describe 'BreakoutParser' do
|
|
982
1009
|
|
983
1010
|
def parse s, h = {}
|
984
1011
|
h[:space_name] = "test_space" unless h.key?(:space_name)
|
985
|
-
BreakoutParser.parse(s,
|
1012
|
+
BreakoutParser.parse(s,
|
1013
|
+
h[:space_name],
|
1014
|
+
h[:site_url],
|
1015
|
+
h[:git_url],
|
1016
|
+
h[:absolute_urls]
|
1017
|
+
).strip
|
986
1018
|
end
|
987
1019
|
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: breakout_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 59
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
9
|
+
- 18
|
10
|
+
version: 0.0.18
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Andrey "Zed" Zaikin
|
@@ -14,16 +15,18 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-08-25 00:00:00 +04:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: rspec
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
27
|
- - ">="
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 13
|
27
30
|
segments:
|
28
31
|
- 1
|
29
32
|
- 2
|
@@ -40,9 +43,11 @@ extensions:
|
|
40
43
|
extra_rdoc_files:
|
41
44
|
- ChangeLog
|
42
45
|
- LICENSE
|
46
|
+
- README
|
43
47
|
files:
|
44
48
|
- ChangeLog
|
45
49
|
- LICENSE
|
50
|
+
- README
|
46
51
|
- ext/breakout_parser/depend
|
47
52
|
- ext/breakout_parser/extconf.rb
|
48
53
|
- ext/breakout_parser/lex.yy.c
|
@@ -55,6 +60,7 @@ files:
|
|
55
60
|
- ext/breakout_parser/ruby_ext.c
|
56
61
|
- ext/breakout_parser/yywrap.c
|
57
62
|
- lib/breakout_parser.rb
|
63
|
+
- spec/parser_spec.rb
|
58
64
|
has_rdoc: true
|
59
65
|
homepage: http://assembla.com
|
60
66
|
licenses: []
|
@@ -65,23 +71,27 @@ rdoc_options:
|
|
65
71
|
require_paths:
|
66
72
|
- lib
|
67
73
|
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
68
75
|
requirements:
|
69
76
|
- - ">="
|
70
77
|
- !ruby/object:Gem::Version
|
78
|
+
hash: 3
|
71
79
|
segments:
|
72
80
|
- 0
|
73
81
|
version: "0"
|
74
82
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
75
84
|
requirements:
|
76
85
|
- - ">="
|
77
86
|
- !ruby/object:Gem::Version
|
87
|
+
hash: 3
|
78
88
|
segments:
|
79
89
|
- 0
|
80
90
|
version: "0"
|
81
91
|
requirements: []
|
82
92
|
|
83
93
|
rubyforge_project:
|
84
|
-
rubygems_version: 1.3.
|
94
|
+
rubygems_version: 1.3.7
|
85
95
|
signing_key:
|
86
96
|
specification_version: 3
|
87
97
|
summary: BreakoutParser
|