From 253c4730f9387a9571a572e725c50cf82520eca1 Mon Sep 17 00:00:00 2001 From: Jeremy Edberg Date: Mon, 17 May 2010 12:40:41 -0700 Subject: [PATCH] * Add services and scripts to public repos for ease of reddit installation * bring discount up to date * fix consistency errors in the self-serve traffic page --- r2/Makefile | 11 +- r2/example.ini | 4 + r2/r2/controllers/api.py | 54 ++- r2/r2/controllers/front.py | 5 +- r2/r2/controllers/listingcontroller.py | 22 +- r2/r2/controllers/post.py | 2 +- r2/r2/controllers/validator/validator.py | 5 + r2/r2/lib/amqp.py | 191 +++++--- r2/r2/lib/c/reddit-discount-wrapper.c | 2 +- r2/r2/lib/contrib/discount-1.6.0/VERSION | 1 - r2/r2/lib/contrib/discount-1.6.0/config.md | 5 - .../contrib/discount-1.6.0/tests/backslash.t | 35 -- r2/r2/lib/contrib/discount-1.6.0/tests/code.t | 39 -- .../lib/contrib/discount-1.6.0/tests/crash.t | 57 --- r2/r2/lib/contrib/discount-1.6.0/tests/flow.t | 52 --- .../contrib/discount-1.6.0/tests/footnotes.t | 34 -- .../contrib/discount-1.6.0/tests/linkypix.t | 31 -- r2/r2/lib/contrib/discount-1.6.0/tests/misc.t | 33 -- r2/r2/lib/contrib/discount-1.6.0/tests/para.t | 38 -- .../contrib/discount-1.6.0/tests/paranoia.t | 31 -- .../contrib/discount-1.6.0/tests/reparse.t | 34 -- .../lib/contrib/discount-1.6.0/tests/style.t | 32 -- r2/r2/lib/contrib/discount-1.6.0/tests/toc.t | 41 -- .../{discount-1.6.0 => discount}/COPYRIGHT | 0 .../{discount-1.6.0 => discount}/CREDITS | 0 .../{discount-1.6.0 => discount}/Csio.c | 0 .../{discount-1.6.0 => discount}/INSTALL | 0 .../{discount-1.6.0 => discount}/Makefile | 39 +- .../{discount-1.6.0 => discount}/Makefile.in | 31 +- .../{discount-1.6.0 => discount}/Plan9/README | 0 .../Plan9/markdown.1 | 0 .../Plan9/markdown.2 | 0 .../Plan9/markdown.6 | 0 .../{discount-1.6.0 => discount}/Plan9/mkfile | 0 .../{discount-1.6.0 => discount}/README | 0 r2/r2/lib/contrib/discount/VERSION | 1 + .../{discount-1.6.0 => discount}/amalloc.c | 0 .../{discount-1.6.0 => discount}/amalloc.h | 0 r2/r2/lib/contrib/discount/basename.c | 43 ++ .../{discount-1.6.0 => discount}/config.cmd | 0 .../{discount-1.6.0 => discount}/config.h | 5 +- .../{discount-1.6.0 => discount}/config.log | 15 +- .../{discount-1.6.0 => discount}/config.mak | 0 r2/r2/lib/contrib/discount/config.md | 5 + .../{discount-1.6.0 => discount}/config.sub | 7 +- .../configure.inc | 39 +- .../{discount-1.6.0 => discount}/configure.sh | 2 +- .../{discount-1.6.0 => discount}/css.c | 0 .../{discount-1.6.0 => discount}/cstring.h | 0 .../{discount-1.6.0 => discount}/docheader.c | 0 .../{discount-1.6.0 => discount}/dumptree.c | 0 r2/r2/lib/contrib/discount/emmatch.c | 188 ++++++++ .../{discount-1.6.0 => discount}/generate.c | 432 +++++++----------- .../{discount-1.6.0 => discount}/main.c | 18 +- .../{discount-1.6.0 => discount}/makepage.c | 0 .../{discount-1.6.0 => discount}/markdown.1 | 0 .../markdown.1.in | 0 .../{discount-1.6.0 => discount}/markdown.3 | 1 + .../{discount-1.6.0 => discount}/markdown.7 | 1 + .../{discount-1.6.0 => discount}/markdown.c | 34 +- .../{discount-1.6.0 => discount}/markdown.h | 20 +- r2/r2/lib/contrib/discount/mkd-callbacks.3 | 71 +++ .../mkd-extensions.7 | 1 + .../mkd-functions.3 | 0 .../{discount-1.6.0 => discount}/mkd-line.3 | 0 .../{discount-1.6.0 => discount}/mkd2html.c | 0 .../{discount-1.6.0 => discount}/mkdio.c | 30 +- .../{discount-1.6.0 => discount}/mkdio.h | 12 +- .../{discount-1.6.0 => discount}/resource.c | 0 .../tests/autolink.t | 27 +- .../tests/automatic.t | 38 +- r2/r2/lib/contrib/discount/tests/backslash.t | 16 + r2/r2/lib/contrib/discount/tests/callbacks.t | 17 + .../tests/chrome.text | 0 r2/r2/lib/contrib/discount/tests/code.t | 31 ++ .../tests/compat.t | 26 +- r2/r2/lib/contrib/discount/tests/crash.t | 30 ++ .../{discount-1.6.0 => discount}/tests/div.t | 28 +- .../{discount-1.6.0 => discount}/tests/dl.t | 26 +- .../tests/embedlinks.text | 0 .../tests/emphasis.t | 27 +- r2/r2/lib/contrib/discount/tests/flow.t | 33 ++ r2/r2/lib/contrib/discount/tests/footnotes.t | 16 + r2/r2/lib/contrib/discount/tests/functions.sh | 77 ++++ .../tests/header.t | 28 +- .../{discount-1.6.0 => discount}/tests/html.t | 69 ++- .../tests/links.text | 0 .../tests/linkylinky.t | 27 +- r2/r2/lib/contrib/discount/tests/linkypix.t | 21 + .../{discount-1.6.0 => discount}/tests/list.t | 25 +- .../tests/list3deep.t | 25 +- r2/r2/lib/contrib/discount/tests/misc.t | 12 + .../tests/pandoc.t | 28 +- r2/r2/lib/contrib/discount/tests/para.t | 19 + r2/r2/lib/contrib/discount/tests/paranoia.t | 12 + .../tests/peculiarities.t | 26 +- .../tests/pseudo.t | 29 +- r2/r2/lib/contrib/discount/tests/reddit.t | 27 ++ r2/r2/lib/contrib/discount/tests/reparse.t | 14 + .../tests/schiraldi.t | 35 +- .../tests/smarty.t | 28 +- .../tests/snakepit.t | 27 +- r2/r2/lib/contrib/discount/tests/style.t | 17 + .../tests/syntax.text | 0 .../tests/tables.t | 27 +- .../tests/tabstop.t | 26 +- r2/r2/lib/contrib/discount/tests/toc.t | 21 + .../{discount-1.6.0 => discount}/tests/xml.t | 29 +- .../{discount-1.6.0 => discount}/theme.1 | 0 .../{discount-1.6.0 => discount}/theme.c | 0 .../{discount-1.6.0 => discount}/toc.c | 0 .../{discount-1.6.0 => discount}/tools/cols.c | 0 .../{discount-1.6.0 => discount}/tools/echo.c | 0 .../{discount-1.6.0 => discount}/version.c | 0 .../{discount-1.6.0 => discount}/version.c.in | 0 .../{discount-1.6.0 => discount}/xml.c | 0 .../{discount-1.6.0 => discount}/xmlpage.c | 0 r2/r2/lib/db/queries.py | 99 ++-- r2/r2/lib/db/query_queue.py | 88 ++-- r2/r2/lib/db/thing.py | 14 +- r2/r2/lib/media.py | 29 +- r2/r2/lib/pages/pages.py | 20 +- r2/r2/lib/pages/things.py | 5 +- r2/r2/lib/promote.py | 9 + r2/r2/lib/strings.py | 1 + r2/r2/lib/utils/utils.py | 5 +- r2/r2/models/account.py | 2 +- r2/r2/models/admintools.py | 4 +- r2/r2/models/bidding.py | 9 +- r2/r2/models/link.py | 3 +- r2/r2/models/subreddit.py | 2 +- r2/r2/public/static/js/reddit.js | 28 +- r2/r2/templates/comment.html | 1 + r2/r2/templates/prefupdate.html | 1 - r2/r2/templates/thingupdater.html | 2 +- r2/run.ini | 1 + r2/setup.py | 6 +- scripts/broken_things.sh | 5 + scripts/catchup_batch_queries.sh | 4 + scripts/log_q.py | 67 ++- scripts/make_ads.sh | 30 -- scripts/rising.sh | 4 + scripts/send_mail.sh | 4 + scripts/update_promos.sh | 4 + srv/cassandra/log/run | 3 + srv/cassandra/run | 7 + srv/comments_q/log/run | 3 + srv/comments_q/run | 6 + srv/commentstree_q/log/run | 3 + srv/commentstree_q/run | 6 + srv/haproxy/haproxy.conf | 74 +++ srv/haproxy/log/run | 3 + srv/haproxy/run | 7 + srv/log_stub/log/run | 3 + srv/log_stub/run | 8 + srv/memcached/log/run | 3 + srv/memcached/run | 4 + srv/query_queue_worker1/log/run | 3 + srv/query_queue_worker1/run | 6 + srv/reddit-app01/log/run | 3 + srv/reddit-app01/run | 5 + srv/reddit-app02/log/run | 3 + srv/reddit-app02/run | 5 + srv/scraper_q/log/run | 3 + srv/scraper_q/run | 11 + srv/searchchanges_stub/log/run | 3 + srv/searchchanges_stub/run | 8 + srv/servicemonitor/log/run | 3 + srv/servicemonitor/run | 5 + srv/vote_q/log/run | 3 + srv/vote_q/run | 9 + 171 files changed, 1763 insertions(+), 1602 deletions(-) delete mode 100644 r2/r2/lib/contrib/discount-1.6.0/VERSION delete mode 100755 r2/r2/lib/contrib/discount-1.6.0/config.md delete mode 100644 r2/r2/lib/contrib/discount-1.6.0/tests/backslash.t delete mode 100644 r2/r2/lib/contrib/discount-1.6.0/tests/code.t delete mode 100644 r2/r2/lib/contrib/discount-1.6.0/tests/crash.t delete mode 100644 r2/r2/lib/contrib/discount-1.6.0/tests/flow.t delete mode 100644 r2/r2/lib/contrib/discount-1.6.0/tests/footnotes.t delete mode 100644 r2/r2/lib/contrib/discount-1.6.0/tests/linkypix.t delete mode 100644 r2/r2/lib/contrib/discount-1.6.0/tests/misc.t delete mode 100644 r2/r2/lib/contrib/discount-1.6.0/tests/para.t delete mode 100644 r2/r2/lib/contrib/discount-1.6.0/tests/paranoia.t delete mode 100644 r2/r2/lib/contrib/discount-1.6.0/tests/reparse.t delete mode 100644 r2/r2/lib/contrib/discount-1.6.0/tests/style.t delete mode 100644 r2/r2/lib/contrib/discount-1.6.0/tests/toc.t rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/COPYRIGHT (100%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/CREDITS (100%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/Csio.c (100%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/INSTALL (100%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/Makefile (60%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/Makefile.in (67%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/Plan9/README (100%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/Plan9/markdown.1 (100%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/Plan9/markdown.2 (100%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/Plan9/markdown.6 (100%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/Plan9/mkfile (100%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/README (100%) create mode 100644 r2/r2/lib/contrib/discount/VERSION rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/amalloc.c (100%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/amalloc.h (100%) create mode 100644 r2/r2/lib/contrib/discount/basename.c rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/config.cmd (100%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/config.h (77%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/config.log (63%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/config.mak (100%) create mode 100755 r2/r2/lib/contrib/discount/config.md rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/config.sub (76%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/configure.inc (98%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/configure.sh (99%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/css.c (100%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/cstring.h (100%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/docheader.c (100%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/dumptree.c (100%) mode change 100755 => 100644 create mode 100644 r2/r2/lib/contrib/discount/emmatch.c rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/generate.c (83%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/main.c (93%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/makepage.c (100%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/markdown.1 (100%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/markdown.1.in (100%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/markdown.3 (99%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/markdown.7 (99%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/markdown.c (97%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/markdown.h (90%) create mode 100644 r2/r2/lib/contrib/discount/mkd-callbacks.3 rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/mkd-extensions.7 (99%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/mkd-functions.3 (100%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/mkd-line.3 (100%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/mkd2html.c (100%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/mkdio.c (92%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/mkdio.h (90%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/resource.c (100%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/tests/autolink.t (67%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/tests/automatic.t (60%) create mode 100644 r2/r2/lib/contrib/discount/tests/backslash.t create mode 100644 r2/r2/lib/contrib/discount/tests/callbacks.t rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/tests/chrome.text (100%) create mode 100644 r2/r2/lib/contrib/discount/tests/code.t rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/tests/compat.t (57%) create mode 100644 r2/r2/lib/contrib/discount/tests/crash.t rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/tests/div.t (66%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/tests/dl.t (61%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/tests/embedlinks.text (100%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/tests/emphasis.t (63%) create mode 100644 r2/r2/lib/contrib/discount/tests/flow.t create mode 100644 r2/r2/lib/contrib/discount/tests/footnotes.t create mode 100644 r2/r2/lib/contrib/discount/tests/functions.sh rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/tests/header.t (64%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/tests/html.t (75%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/tests/links.text (100%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/tests/linkylinky.t (87%) create mode 100644 r2/r2/lib/contrib/discount/tests/linkypix.t rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/tests/list.t (84%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/tests/list3deep.t (65%) create mode 100644 r2/r2/lib/contrib/discount/tests/misc.t rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/tests/pandoc.t (64%) create mode 100644 r2/r2/lib/contrib/discount/tests/para.t create mode 100644 r2/r2/lib/contrib/discount/tests/paranoia.t rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/tests/peculiarities.t (60%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/tests/pseudo.t (58%) create mode 100644 r2/r2/lib/contrib/discount/tests/reddit.t create mode 100644 r2/r2/lib/contrib/discount/tests/reparse.t rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/tests/schiraldi.t (88%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/tests/smarty.t (73%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/tests/snakepit.t (62%) create mode 100644 r2/r2/lib/contrib/discount/tests/style.t rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/tests/syntax.text (100%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/tests/tables.t (84%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/tests/tabstop.t (52%) create mode 100644 r2/r2/lib/contrib/discount/tests/toc.t rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/tests/xml.t (57%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/theme.1 (100%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/theme.c (100%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/toc.c (100%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/tools/cols.c (100%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/tools/echo.c (100%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/version.c (100%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/version.c.in (100%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/xml.c (100%) rename r2/r2/lib/contrib/{discount-1.6.0 => discount}/xmlpage.c (100%) create mode 120000 r2/run.ini create mode 100755 scripts/broken_things.sh create mode 100755 scripts/catchup_batch_queries.sh delete mode 100755 scripts/make_ads.sh create mode 100755 scripts/rising.sh create mode 100755 scripts/send_mail.sh create mode 100755 scripts/update_promos.sh create mode 100755 srv/cassandra/log/run create mode 100755 srv/cassandra/run create mode 100755 srv/comments_q/log/run create mode 100755 srv/comments_q/run create mode 100755 srv/commentstree_q/log/run create mode 100755 srv/commentstree_q/run create mode 100644 srv/haproxy/haproxy.conf create mode 100755 srv/haproxy/log/run create mode 100755 srv/haproxy/run create mode 100755 srv/log_stub/log/run create mode 100755 srv/log_stub/run create mode 100755 srv/memcached/log/run create mode 100755 srv/memcached/run create mode 100755 srv/query_queue_worker1/log/run create mode 100755 srv/query_queue_worker1/run create mode 100755 srv/reddit-app01/log/run create mode 100755 srv/reddit-app01/run create mode 100755 srv/reddit-app02/log/run create mode 100755 srv/reddit-app02/run create mode 100755 srv/scraper_q/log/run create mode 100755 srv/scraper_q/run create mode 100755 srv/searchchanges_stub/log/run create mode 100755 srv/searchchanges_stub/run create mode 100755 srv/servicemonitor/log/run create mode 100755 srv/servicemonitor/run create mode 100755 srv/vote_q/log/run create mode 100755 srv/vote_q/run diff --git a/r2/Makefile b/r2/Makefile index 770d847237..4be93dfcdf 100644 --- a/r2/Makefile +++ b/r2/Makefile @@ -50,16 +50,19 @@ RTLCSS = $(CSSTARGETS:.css=-rtl.css) $(MAINCSS:.css=-rtl.css) MD5S = $(JSTARGETS:=.md5) $(CSSTARGETS:=.md5) $(MAINCSS:=.md5) $(RTLCSS:=.md5) -ifdef PRIVATEREPOS INIUPDATE = $(wildcard *.update) INIS = $(INIUPDATE:.update=.ini) %.ini: %.update - ln -sf `pwd`/$< $(PRIVATEREPOS)/.. - make -C $(PRIVATEREPOS)/.. $@ - ln -sf $(PRIVATEREPOS)/../$@ . +ifneq (,$(PRIVATEREPOS)) + ln -sf `pwd`/$< $(PRIVATEREPOS)/.. + make -C $(PRIVATEREPOS)/.. $@ + ln -sf $(PRIVATEREPOS)/../$@ . +else + ./updateini.py example.ini $< > $@ || rm $@ endif + all: $(JSTARGETS) $(CSSTARGETS) $(MD5S) $(RTLCSS) $(INIS) .PHONY: js css md5 rtl clean all diff --git a/r2/example.ini b/r2/example.ini index 3659b85cd8..43acfd72f5 100644 --- a/r2/example.ini +++ b/r2/example.ini @@ -21,6 +21,9 @@ exception_logging = false log_start = true # enable/disable logging for amqp/rabbitmq amqp_logging = false +# emergency measures: makes the site read only +read_only_mode = false + # -- SECRETS! <-- update these first! -- # global secret SECRET = abcdefghijklmnopqrstuvwxyz0123456789 @@ -191,6 +194,7 @@ tracking_secret = abcdefghijklmnopqrstuvwxyz0123456789 # (secure) payment domain payment_domain = http://pay.localhost/ ad_domain = http://localhost +sponsors = # authorize.net credentials authorizenetname = authorizenetkey = diff --git a/r2/r2/controllers/api.py b/r2/r2/controllers/api.py index 8b9213bc91..f999342e6e 100644 --- a/r2/r2/controllers/api.py +++ b/r2/r2/controllers/api.py @@ -192,7 +192,6 @@ def POST_compose(self, form, jquery, to, subject, body, ip): ip = ValidIP(), sr = VSubmitSR('sr'), url = VUrl(['url', 'sr']), - banmsg = VOkayDomain('url'), title = VTitle('title'), save = VBoolean('save'), selftext = VMarkdown('text'), @@ -229,17 +228,23 @@ def POST_submit(self, form, jquery, url, selftext, kind, title, if not should_ratelimit: c.errors.remove((errors.RATELIMIT, 'ratelimit')) + banmsg = None + if kind == 'link': + check_domain = True + # check for no url, or clear that error field on return if form.has_errors("url", errors.NO_URL, errors.BAD_URL): pass elif form.has_errors("url", errors.ALREADY_SUB): + check_domain = False form.redirect(url[0].already_submitted_link) # check for title, otherwise look it up and return it elif form.has_errors("title", errors.NO_TEXT): pass - banmsg = is_banned_domain(url) + if check_domain: + banmsg = is_banned_domain(url) # Uncomment if we want to let spammers know we're on to them # if banmsg: @@ -248,7 +253,6 @@ def POST_submit(self, form, jquery, url, selftext, kind, title, else: form.has_errors('text', errors.TOO_LONG) - banmsg = None if form.has_errors("title", errors.TOO_LONG, errors.NO_TEXT): pass @@ -261,21 +265,24 @@ def POST_submit(self, form, jquery, url, selftext, kind, title, if should_ratelimit: filled_quota = c.user.quota_full('link') - if filled_quota is not None and not c.user._spam: - log_text ("over-quota", - "%s just went over their per-%s quota" % - (c.user.name, filled_quota), "info") + if filled_quota is not None: + if c.user._spam: + msg = strings.generic_quota_msg + else: + log_text ("over-quota", + "%s just went over their per-%s quota" % + (c.user.name, filled_quota), "info") - compose_link = ("/message/compose?to=%23" + sr.name + - "&subject=Exemption+request") + compose_link = ("/message/compose?to=%23" + sr.name + + "&subject=Exemption+request") - verify_link = "/verify?reason=submit" + verify_link = "/verify?reason=submit" - if c.user.email_verified: - msg = strings.verified_quota_msg % dict(link=compose_link) - else: - msg = strings.unverified_quota_msg % dict(link1=verify_link, - link2=compose_link) + if c.user.email_verified: + msg = strings.verified_quota_msg % dict(link=compose_link) + else: + msg = strings.unverified_quota_msg % dict(link1=verify_link, + link2=compose_link) md = safemarkdown(msg) form.set_html(".status", md) @@ -481,9 +488,6 @@ def POST_unfriend(self, nuser, iuser, container, type): if type in ("moderator", "contributor"): Subreddit.special_reddits(victim, type, _update=True) - if type in ("moderator", "contributor"): - Subreddit.special_reddits(iuser or nuser, type, _update=True) - @validatedForm(VUser(), @@ -909,6 +913,9 @@ def POST_vote(self, dir, thing, ip, vote_type): g.log.debug("POST_vote: ignoring old vote on %s" % thing._fullname) store = False + if getattr(c.user, "suspicious", False): + g.log.info("%s cast a %d vote on %s", c.user.name, dir, thing._fullname) + dir = (True if dir > 0 else False if dir < 0 else None) @@ -1132,7 +1139,6 @@ def POST_upload_sr_img(self, file, header, sponsor, name, form_id): over_18 = VBoolean('over_18'), allow_top = VBoolean('allow_top'), show_media = VBoolean('show_media'), - use_whitelist = VBoolean('use_whitelist'), type = VOneOf('type', ('public', 'private', 'restricted')), ip = ValidIP(), sponsor_text =VLength('sponsorship-text', max_length = 500), @@ -1520,15 +1526,20 @@ def POST_subscribe(self, action, sr): # Anyone can leave. if action != 'sub' or sr.can_comment(c.user): self._subscribe(sr, action == 'sub') - + def _subscribe(self, sr, sub): Subreddit.subscribe_defaults(c.user) + sub_key = "subscription-%s-%s" % (c.user.name, sr.name) + if sub: - if sr.add_subscriber(c.user): + if not g.cache.add(sub_key, True): + g.log.warning("Double-subscribe for %s?" % sub_key) + elif sr.add_subscriber(c.user): sr._incr('_ups', 1) else: if sr.remove_subscriber(c.user): + g.cache.delete(sub_key) sr._incr('_ups', -1) changed(sr) @@ -1538,7 +1549,6 @@ def _subscribe(self, sr, sub): def POST_disable_lang(self, tr): if tr: tr._is_enabled = False - @noresponse(VAdmin(), tr = VTranslation("id")) diff --git a/r2/r2/controllers/front.py b/r2/r2/controllers/front.py index 28d36bb176..1118f83e5d 100644 --- a/r2/r2/controllers/front.py +++ b/r2/r2/controllers/front.py @@ -523,7 +523,10 @@ def _search(self, query_obj, num, after, reverse, count=0): try: res = listing.listing() except SolrError, e: - errmsg = "SolrError: %r %r" % (e, query_obj) + try: + errmsg = "SolrError: %r %r" % (e, query_obj) + except UnicodeEncodeError: + errmsg = "SolrError involving unicode" if (str(e) == 'None'): # Production error logs only get non-None errors diff --git a/r2/r2/controllers/listingcontroller.py b/r2/r2/controllers/listingcontroller.py index d91de7df7a..487485245a 100644 --- a/r2/r2/controllers/listingcontroller.py +++ b/r2/r2/controllers/listingcontroller.py @@ -238,6 +238,13 @@ def spotlight(self): spotlight_links, pos = promote.insert_promoted(spotlight_links, pos) trial = populate_spotlight() + # Need to do this again, because if there was a duplicate removed, + # pos might be pointing outside the list. + if not spotlight_links: + pos = 0 + elif pos != 0: + pos = pos % len(spotlight_links) + if trial: spotlight_links.insert(pos, trial._fullname) @@ -268,9 +275,16 @@ def wrap(item): num = organic.organic_length, skip = True, keep_fn = keep_fn) + try: + vislink = spotlight_links[pos] + except IndexError: + g.log.error("spotlight_links = %r" % spotlight_links) + g.log.error("pos = %d" % pos) + raise + s = SpotlightListing(b, spotlight_links = spotlight_links, - visible_link = spotlight_links[pos], + visible_link = vislink, max_num = self.listing_obj.max_num, max_score = self.listing_obj.max_score).listing() @@ -367,10 +381,10 @@ def keep(item): return keep def query(self): + res = None if self.sort == 'rising': - return get_rising(c.site) - else: - return c.site.get_links('new', 'all') + res = get_rising(c.site) + return res or c.site.get_links('new', 'all') @validate(sort = VMenu('controller', NewMenu)) def GET_listing(self, sort, **env): diff --git a/r2/r2/controllers/post.py b/r2/r2/controllers/post.py index 130ac3754e..11e7a7cc8b 100644 --- a/r2/r2/controllers/post.py +++ b/r2/r2/controllers/post.py @@ -36,7 +36,7 @@ def api_wrapper(self, kw): def set_options(self, all_langs, pref_lang, **kw): if c.errors.errors: print "fucker" - raise "broken" + return if all_langs == 'all': langs = 'all' diff --git a/r2/r2/controllers/validator/validator.py b/r2/r2/controllers/validator/validator.py index 8bdeccd44d..50516b4e5d 100644 --- a/r2/r2/controllers/validator/validator.py +++ b/r2/r2/controllers/validator/validator.py @@ -782,6 +782,9 @@ def run(self, url, sr = None): if not url: return self.error(errors.NO_URL) url = utils.sanitize_url(url) + if not url: + return self.error(errors.BAD_URL) + if url == 'self': if self.allow_self: return url @@ -996,6 +999,8 @@ def ratelimit(self, rate_user = False, rate_ip = False, prefix = "rate_", to_set = {} if seconds is None: seconds = g.RATELIMIT*60 + if not seconds: + return expire_time = datetime.now(g.tz) + timedelta(seconds = seconds) if rate_user and c.user_is_loggedin: to_set['user' + str(c.user._id36)] = expire_time diff --git a/r2/r2/lib/amqp.py b/r2/r2/lib/amqp.py index 699afdcd58..4485faad1c 100644 --- a/r2/r2/lib/amqp.py +++ b/r2/r2/lib/amqp.py @@ -38,18 +38,15 @@ amqp_host = g.amqp_host amqp_user = g.amqp_user amqp_pass = g.amqp_pass +amqp_exchange = 'reddit_exchange' log = g.log amqp_virtual_host = g.amqp_virtual_host amqp_logging = g.amqp_logging -connection = None -channel = local() -have_init = False - #there are two ways of interacting with this module: add_item and -#handle_items. _add_item (the internal function for adding items to -#amqp that are added using add_item) might block for an arbitrary -#amount of time while trying to get a connection amqp. +#handle_items/consume_items. _add_item (the internal function for +#adding items to amqp that are added using add_item) might block for +#an arbitrary amount of time while trying to get a connection to amqp. class Worker: def __init__(self): @@ -77,76 +74,85 @@ def join(self): worker = Worker() -def get_connection(): - global connection - global have_init +class ConnectionManager(local): + # There should be only two threads that ever talk to AMQP: the + # worker thread and the foreground thread (whether consuming queue + # items or a shell). This class is just a wrapper to make sure + # that they get separate connections + def __init__(self): + self.connection = None + self.channel = None + self.have_init = False - while not connection: - try: - connection = amqp.Connection(host = amqp_host, - userid = amqp_user, - password = amqp_pass, - virtual_host = amqp_virtual_host, - insist = False) - except (socket.error, IOError): - print 'error connecting to amqp %s @ %s' % (amqp_user, amqp_host) - time.sleep(1) - - # don't run init_queue until someone actually needs it. this - # allows the app server to start and serve most pages if amqp - # isn't running - if not have_init: - init_queue() - have_init = True - -def get_channel(reconnect = False): - global connection - global channel - - # Periodic (and increasing with uptime) errors appearing when - # connection object is still present, but appears to have been - # closed. This checks that the the connection is still open. - if connection and connection.channels is None: - log.error("Error: amqp.py, connection object with no available channels. Reconnecting...") - connection = None - - if not connection or reconnect: - channel.chan = None - connection = None - get_connection() - - if not getattr(channel, 'chan', None): - channel.chan = connection.channel() - return channel.chan - - -def init_queue(): - from r2.lib.queues import RedditQueueMap + def get_connection(self): + while not self.connection: + try: + self.connection = amqp.Connection(host = amqp_host, + userid = amqp_user, + password = amqp_pass, + virtual_host = amqp_virtual_host, + insist = False) + except (socket.error, IOError): + print 'error connecting to amqp %s @ %s' % (amqp_user, amqp_host) + time.sleep(1) + + # don't run init_queue until someone actually needs it. this + # allows the app server to start and serve most pages if amqp + # isn't running + if not self.have_init: + self.init_queue() + self.have_init = True + + return self.connection - exchange = 'reddit_exchange' + def get_channel(self, reconnect = False): + # Periodic (and increasing with uptime) errors appearing when + # connection object is still present, but appears to have been + # closed. This checks that the the connection is still open. + if self.connection and self.connection.channels is None: + log.error("Error: amqp.py, connection object with no available channels. Reconnecting...") + self.connection = None - chan = get_channel() + if not self.connection or reconnect: + self.connection = None + self.channel = None + self.get_connection() - RedditQueueMap(exchange, chan).init() + if not self.channel: + self.channel = self.connection.channel() + return self.channel -def _add_item(routing_key, body, message_id = None): + def init_queue(self): + from r2.lib.queues import RedditQueueMap + + chan = self.get_channel() + + RedditQueueMap(amqp_exchange, chan).init() + +connection_manager = ConnectionManager() + +DELIVERY_TRANSIENT = 1 +DELIVERY_DURABLE = 2 + +def _add_item(routing_key, body, message_id = None, + delivery_mode = DELIVERY_DURABLE): """adds an item onto a queue. If the connection to amqp is lost it will try to reconnect and then call itself again.""" if not amqp_host: log.error("Ignoring amqp message %r to %r" % (body, routing_key)) return - chan = get_channel() + chan = connection_manager.get_channel() msg = amqp.Message(body, timestamp = datetime.now(), - delivery_mode = 2) + delivery_mode = delivery_mode) if message_id: msg.properties['message_id'] = message_id try: chan.basic_publish(msg, - exchange = 'reddit_exchange', + exchange = amqp_exchange, routing_key = routing_key) except Exception as e: if e.errno == errno.EPIPE: @@ -155,22 +161,60 @@ def _add_item(routing_key, body, message_id = None): else: raise -def add_item(routing_key, body, message_id = None): +def add_item(routing_key, body, message_id = None, delivery_mode = DELIVERY_DURABLE): if amqp_host and amqp_logging: log.debug("amqp: adding item %r to %r" % (body, routing_key)) - worker.do(_add_item, routing_key, body, message_id = message_id) + worker.do(_add_item, routing_key, body, message_id = message_id, + delivery_mode = delivery_mode) def add_kw(routing_key, **kw): add_item(routing_key, pickle.dumps(kw)) +def consume_items(queue, callback, verbose=True): + """A lighter-weight version of handle_items that uses AMQP's + basic.consume instead of basic.get. Callback is only passed a + single items at a time. This is more efficient than + handle_items when the queue is likely to be occasionally empty + or if batching the received messages is not necessary.""" + chan = connection_manager.get_channel() + + def _callback(msg): + if verbose: + count_str = '' + if 'message_count' in msg.delivery_info: + # the count from the last message, if the count is + # available + count_str = '(%d remaining)' % msg.delivery_info['message_count'] + + print "%s: 1 item %s" % (queue, count_str) + + g.reset_caches() + ret = callback(msg) + msg.channel.basic_ack(msg.delivery_tag) + sys.stdout.flush() + return ret + + chan.basic_consume(queue=queue, callback=_callback) + + try: + while chan.callbacks: + try: + chan.wait() + except KeyboardInterrupt: + chan.close() + break + finally: + if chan.is_open: + chan.close() + def handle_items(queue, callback, ack = True, limit = 1, drain = False, verbose=True, sleep_time = 1): """Call callback() on every item in a particular queue. If the connection to the queue is lost, it will die. Intended to be used as a long-running process.""" - chan = get_channel() + chan = connection_manager.get_channel() countdown = None while True: @@ -212,8 +256,8 @@ def handle_items(queue, callback, ack = True, limit = 1, drain = False, callback(items, chan) if ack: - for item in items: - chan.basic_ack(item.delivery_tag) + # ack *all* outstanding messages + chan.basic_ack(0, multiple=True) # flush any log messages printed by the callback sys.stdout.flush() @@ -226,5 +270,24 @@ def handle_items(queue, callback, ack = True, limit = 1, drain = False, def empty_queue(queue): """debug function to completely erase the contents of a queue""" - chan = get_channel() + chan = connection_manager.get_channel() chan.queue_purge(queue) + + +def _test_setup(test_q = 'test_q'): + from r2.lib.queues import RedditQueueMap + chan = connection_manager.get_channel() + rqm = RedditQueueMap(amqp_exchange, chan) + rqm._q(test_q, durable=False, auto_delete=True, self_refer=True) + return chan + +def test_consume(test_q = 'test_q'): + chan = _test_setup() + def _print(msg): + print msg.body + consume_items(test_q, _print) + +def test_produce(test_q = 'test_q', msg_body = 'hello, world!'): + _test_setup() + add_item(test_q, msg_body) + worker.join() diff --git a/r2/r2/lib/c/reddit-discount-wrapper.c b/r2/r2/lib/c/reddit-discount-wrapper.c index 2e263ddefb..d95b46f7bb 100644 --- a/r2/r2/lib/c/reddit-discount-wrapper.c +++ b/r2/r2/lib/c/reddit-discount-wrapper.c @@ -71,7 +71,7 @@ reddit_discount_wrap(const char * text, int nofollow, const char * target, MKD_NO_EXT | MKD_AUTOLINK | MKD_SAFELINK); mkd_e_flags (mmiot, &cb_flagmaker); - mkd_e_context(mmiot, &opts); + mkd_e_data(mmiot, &opts); *size = mkd_document(mmiot, html); *v_mmiot = mmiot; diff --git a/r2/r2/lib/contrib/discount-1.6.0/VERSION b/r2/r2/lib/contrib/discount-1.6.0/VERSION deleted file mode 100644 index 9c6d6293b1..0000000000 --- a/r2/r2/lib/contrib/discount-1.6.0/VERSION +++ /dev/null @@ -1 +0,0 @@ -1.6.1 diff --git a/r2/r2/lib/contrib/discount-1.6.0/config.md b/r2/r2/lib/contrib/discount-1.6.0/config.md deleted file mode 100755 index 226af3738b..0000000000 --- a/r2/r2/lib/contrib/discount-1.6.0/config.md +++ /dev/null @@ -1,5 +0,0 @@ -#! /bin/sh -# script generated Fri Jan 29 13:52:24 PST 2010 by configure.sh - -test -d "$1" || mkdir -p "$1" -exit 0 diff --git a/r2/r2/lib/contrib/discount-1.6.0/tests/backslash.t b/r2/r2/lib/contrib/discount-1.6.0/tests/backslash.t deleted file mode 100644 index 8fde539c85..0000000000 --- a/r2/r2/lib/contrib/discount-1.6.0/tests/backslash.t +++ /dev/null @@ -1,35 +0,0 @@ -./echo "backslash escapes" - -rc=0 -MARKDOWN_FLAGS= - -try() { - unset FLAGS - case "$1" in - -*) FLAGS=$1 - shift ;; - esac - - ./echo -n " $1" '..................................' | ./cols 36 - - Q=`./echo "$2" | ./markdown $FLAGS` - - if [ "$3" = "$Q" ]; then - ./echo " ok" - else - ./echo " FAILED" - ./echo "wanted: $3" - ./echo "got: $Q" - rc=1 - fi -} - -try 'backslashes in []()' '[foo](http://\this\is\.a\test\(here\))' \ -'

foo

' - -try -fautolink 'autolink url with trailing \' \ - 'http://a.com/\' \ - '

http://a.com/\

' - - -exit $rc diff --git a/r2/r2/lib/contrib/discount-1.6.0/tests/code.t b/r2/r2/lib/contrib/discount-1.6.0/tests/code.t deleted file mode 100644 index ed460f959d..0000000000 --- a/r2/r2/lib/contrib/discount-1.6.0/tests/code.t +++ /dev/null @@ -1,39 +0,0 @@ -./echo "code blocks" - -rc=0 -MARKDOWN_FLAGS= - -try() { - unset FLAGS - case "$1" in - -*) FLAGS=$1 - shift ;; - esac - - ./echo -n " $1" '..................................' | ./cols 36 - - Q=`./echo "$2" | ./markdown $FLAGS` - - - if [ "$3" = "$Q" ]; then - ./echo " ok" - else - ./echo " FAILED" - ./echo "wanted: $3" - ./echo "got : $Q" - rc=1 - fi -} - -try 'format for code block html' \ -' this is - code' \ - '
this is
-code
-
' - -try 'unclosed single backtick' '`hi there' '

`hi there

' -try 'unclosed double backtick' '``hi there' '

``hi there

' -try 'remove space around code' '`` hi there ``' '

hi there

' - -exit $rc diff --git a/r2/r2/lib/contrib/discount-1.6.0/tests/crash.t b/r2/r2/lib/contrib/discount-1.6.0/tests/crash.t deleted file mode 100644 index c0443ee348..0000000000 --- a/r2/r2/lib/contrib/discount-1.6.0/tests/crash.t +++ /dev/null @@ -1,57 +0,0 @@ -./echo "crashes" - -rc=0 -MARKDOWN_FLAGS= - -./echo -n ' zero-length input ................ ' - -if ./markdown < /dev/null >/dev/null; then - ./echo "ok" -else - ./echo "FAILED" - rc=1 -fi - -./echo -n ' hanging quote in list ............ ' - -./markdown >/dev/null 2>/dev/null << EOF - * > this should not die - -no. -EOF - -if [ "$?" -eq 0 ]; then - ./echo "ok" -else - ./echo "FAILED" - rc=1 -fi - -./echo -n ' dangling list item ............... ' - -if ./echo ' - ' | ./markdown >/dev/null 2>/dev/null; then - ./echo "ok" -else - ./echo "FAILED" - rc=1 -fi - -./echo -n ' empty []() with baseurl .......... ' - -if ./markdown -bHOHO -s '[]()' >/dev/null 2>/dev/null; then - ./echo "ok" -else - ./echo "FAILED" - rc=1 -fi - -./echo -n ' unclosed html block .............. ' - -if ./echo '/dev/null 2>/dev/null; then - ./echo 'ok' -else - ./echo "FAILED" - rc=1 -fi - -exit $rc diff --git a/r2/r2/lib/contrib/discount-1.6.0/tests/flow.t b/r2/r2/lib/contrib/discount-1.6.0/tests/flow.t deleted file mode 100644 index 3541727acd..0000000000 --- a/r2/r2/lib/contrib/discount-1.6.0/tests/flow.t +++ /dev/null @@ -1,52 +0,0 @@ -./echo "paragraph flow" - -rc=0 -MARKDOWN_FLAGS= - -try() { - unset FLAGS - case "$1" in - -*) FLAGS=$1 - shift ;; - esac - - ./echo -n " $1" '..................................' | ./cols 36 - - Q=`./echo "$2" | ./markdown $FLAGS` - - - if [ "$3" = "$Q" ]; then - ./echo " ok" - else - ./echo " FAILED" - ./echo "wanted: $3" - ./echo "got : $Q" - rc=1 - fi -} - -try 'header followed by paragraph' \ - '###Hello, sailor### -And how are you today?' \ - '

Hello, sailor

- -

And how are you today?

' - -try 'two lists punctuated with a HR' \ - '* A -* * * -* B -* C' \ - ' - - -
- -' - -exit $rc diff --git a/r2/r2/lib/contrib/discount-1.6.0/tests/footnotes.t b/r2/r2/lib/contrib/discount-1.6.0/tests/footnotes.t deleted file mode 100644 index 2fa9e94e98..0000000000 --- a/r2/r2/lib/contrib/discount-1.6.0/tests/footnotes.t +++ /dev/null @@ -1,34 +0,0 @@ -./echo "footnotes" - -rc=0 -MARKDOWN_FLAGS= - -try() { - unset FLAGS - case "$1" in - -*) FLAGS=$1 - shift ;; - esac - - ./echo -n " $1" '..................................' | ./cols 36 - - Q=`./echo "$2" | ./markdown $FLAGS` - - if [ "$3" = "$Q" ]; then - ./echo " ok" - else - ./echo " FAILED" - ./echo "wanted: $3" - ./echo "got : $Q" - rc=1 - fi -} - -try 'a line with multiple []s' '[a][] [b][]:' '

[a][] [b][]:

' -try 'a valid footnote' \ - '[alink][] - -[alink]: link_me' \ - '

alink

' - -exit $rc diff --git a/r2/r2/lib/contrib/discount-1.6.0/tests/linkypix.t b/r2/r2/lib/contrib/discount-1.6.0/tests/linkypix.t deleted file mode 100644 index 59bdfbfc47..0000000000 --- a/r2/r2/lib/contrib/discount-1.6.0/tests/linkypix.t +++ /dev/null @@ -1,31 +0,0 @@ -./echo "embedded images" - -rc=0 -MARKDOWN_FLAGS= - -try() { - unset FLAGS - case "$1" in - -*) FLAGS=$1 - shift ;; - esac - - ./echo -n " $1" '..................................' | ./cols 36 - - Q=`./echo "$2" | ./markdown $FLAGS` - - if [ "$3" = "$Q" ]; then - ./echo " ok" - else - ./echo " FAILED" - ./echo "wanted: $3" - ./echo "got : $Q" - rc=1 - fi -} - -try 'image with size extension' \ - '![picture](pic =200x200)' \ - '

picture

' - -exit $rc diff --git a/r2/r2/lib/contrib/discount-1.6.0/tests/misc.t b/r2/r2/lib/contrib/discount-1.6.0/tests/misc.t deleted file mode 100644 index e437a87127..0000000000 --- a/r2/r2/lib/contrib/discount-1.6.0/tests/misc.t +++ /dev/null @@ -1,33 +0,0 @@ -./echo "misc" - -rc=0 -MARKDOWN_FLAGS= - -try() { - unset FLAGS - case "$1" in - -*) FLAGS=$1 - shift ;; - esac - - ./echo -n " $1" '..................................' | ./cols 36 - - Q=`./echo "$2" | ./markdown $FLAGS` - - - if [ "$3" = "$Q" ]; then - ./echo " ok" - else - ./echo " FAILED" - ./echo "wanted: $3" - ./echo "got : $Q" - rc=1 - fi -} - -try 'single paragraph' 'AAA' '

AAA

' -try '< -> <' '<' '

<

' -try '`>` -> >' '`>`' '

>

' -try '`` ` `` -> `' '`` ` ``' '

`

' - -exit $rc diff --git a/r2/r2/lib/contrib/discount-1.6.0/tests/para.t b/r2/r2/lib/contrib/discount-1.6.0/tests/para.t deleted file mode 100644 index d867454df5..0000000000 --- a/r2/r2/lib/contrib/discount-1.6.0/tests/para.t +++ /dev/null @@ -1,38 +0,0 @@ -./echo "paragraph blocking" - -rc=0 -MARKDOWN_FLAGS= - -try() { - unset FLAGS - case "$1" in - -*) FLAGS=$1 - shift ;; - esac - - ./echo -n " $1" '..................................' | ./cols 36 - - Q=`./echo "$2" | ./markdown $FLAGS` - - - if [ "$3" = "$Q" ]; then - ./echo " ok" - else - ./echo " FAILED" - ./echo "wanted: $3" - ./echo "got : $Q" - rc=1 - fi -} - -try 'paragraph followed by code' \ - 'a - b' \ - '

a

- -
b
-
' - -try 'single-line paragraph' 'a' '

a

' - -exit $rc diff --git a/r2/r2/lib/contrib/discount-1.6.0/tests/paranoia.t b/r2/r2/lib/contrib/discount-1.6.0/tests/paranoia.t deleted file mode 100644 index f2b102484c..0000000000 --- a/r2/r2/lib/contrib/discount-1.6.0/tests/paranoia.t +++ /dev/null @@ -1,31 +0,0 @@ -./echo "paranoia" - -rc=0 -MARKDOWN_FLAGS= - -try() { - unset FLAGS - case "$1" in - -*) FLAGS=$1 - shift ;; - esac - - ./echo -n " $1" '..................................' | ./cols 36 - - Q=`./echo "$2" | ./markdown $FLAGS` - - - if [ "$3" = "$Q" ]; then - ./echo " ok" - else - ./echo " FAILED" - ./echo "wanted: $3" - ./echo "got : $Q" - rc=1 - fi -} - -try -fsafelink 'bogus url (-fsafelink)' '[test](bad:protocol)' '

[test](bad:protocol)

' -try -fnosafelink 'bogus url (-fnosafelink)' '[test](bad:protocol)' '

test

' - -exit $rc diff --git a/r2/r2/lib/contrib/discount-1.6.0/tests/reparse.t b/r2/r2/lib/contrib/discount-1.6.0/tests/reparse.t deleted file mode 100644 index b6bebd8f11..0000000000 --- a/r2/r2/lib/contrib/discount-1.6.0/tests/reparse.t +++ /dev/null @@ -1,34 +0,0 @@ -./echo "footnotes inside reparse sections" - -rc=0 - -try() { - unset FLAGS - case "$1" in - -*) FLAGS=$1 - shift ;; - esac - - ./echo -n " $1" '..................................' | ./cols 36 - - Q=`./echo "$2" | ./markdown $FLAGS` - - - if [ "$3" = "$Q" ]; then - ./echo " ok" - else - ./echo " FAILED" - ./echo "wanted: $3" - ./echo "got : $Q" - rc=1 - fi -} - - -try 'footnote inside [] section' \ - '[![foo][]](bar) - -[foo]: bar2' \ - '

foo

' - -exit $rc diff --git a/r2/r2/lib/contrib/discount-1.6.0/tests/style.t b/r2/r2/lib/contrib/discount-1.6.0/tests/style.t deleted file mode 100644 index 5e2a7352b9..0000000000 --- a/r2/r2/lib/contrib/discount-1.6.0/tests/style.t +++ /dev/null @@ -1,32 +0,0 @@ -./echo "styles" - -rc=0 -MARKDOWN_FLAGS= - -./echo -n ' ' | ./markdown|wc -c` - -if [ $count -eq 1 ]; then - ./echo "ok" -else - ./echo "FAILED" - rc=1 -fi - -./echo -n ' ' - -count=`./echo "$ASK" | ./markdown | wc -c` - -if [ $count -eq 1 ]; then - ./echo "ok" -else - ./echo "FAILED" - rc=1 -fi - -exit $rc diff --git a/r2/r2/lib/contrib/discount-1.6.0/tests/toc.t b/r2/r2/lib/contrib/discount-1.6.0/tests/toc.t deleted file mode 100644 index 6408d4cce4..0000000000 --- a/r2/r2/lib/contrib/discount-1.6.0/tests/toc.t +++ /dev/null @@ -1,41 +0,0 @@ -./echo "table-of-contents support" - -rc=0 -MARKDOWN_FLAGS= - -try() { - unset FLAGS - - case "$1" in - -*) FLAGS=$1 - shift ;; - esac - - ./echo -n " $1" '..................................' | ./cols 36 - - Q=`./echo "$2" | ./markdown $FLAGS` - - if [ "$3" = "$Q" ]; then - ./echo " ok" - else - ./echo " FAILED" - ./echo "wanted: $3" - ./echo "got : $Q" - rc=1 - fi -} - - -try '-T -ftoc' 'table of contents' \ -'#H1 -hi' \ -' - -

H1

- -

hi

' - - -exit $rc diff --git a/r2/r2/lib/contrib/discount-1.6.0/COPYRIGHT b/r2/r2/lib/contrib/discount/COPYRIGHT similarity index 100% rename from r2/r2/lib/contrib/discount-1.6.0/COPYRIGHT rename to r2/r2/lib/contrib/discount/COPYRIGHT diff --git a/r2/r2/lib/contrib/discount-1.6.0/CREDITS b/r2/r2/lib/contrib/discount/CREDITS similarity index 100% rename from r2/r2/lib/contrib/discount-1.6.0/CREDITS rename to r2/r2/lib/contrib/discount/CREDITS diff --git a/r2/r2/lib/contrib/discount-1.6.0/Csio.c b/r2/r2/lib/contrib/discount/Csio.c similarity index 100% rename from r2/r2/lib/contrib/discount-1.6.0/Csio.c rename to r2/r2/lib/contrib/discount/Csio.c diff --git a/r2/r2/lib/contrib/discount-1.6.0/INSTALL b/r2/r2/lib/contrib/discount/INSTALL similarity index 100% rename from r2/r2/lib/contrib/discount-1.6.0/INSTALL rename to r2/r2/lib/contrib/discount/INSTALL diff --git a/r2/r2/lib/contrib/discount-1.6.0/Makefile b/r2/r2/lib/contrib/discount/Makefile similarity index 60% rename from r2/r2/lib/contrib/discount-1.6.0/Makefile rename to r2/r2/lib/contrib/discount/Makefile index d412adb6a2..1d81e559a3 100644 --- a/r2/r2/lib/contrib/discount-1.6.0/Makefile +++ b/r2/r2/lib/contrib/discount/Makefile @@ -13,7 +13,9 @@ SAMPLE_PGMS+= theme MKDLIB=libmarkdown.a OBJS=mkdio.o markdown.o dumptree.o generate.o \ resource.o docheader.o version.o toc.o css.o \ - xml.o Csio.o xmlpage.o + xml.o Csio.o xmlpage.o basename.o emmatch.o + +MAN3PAGES=mkd-callbacks.3 mkd-functions.3 markdown.3 mkd-line.3 all: $(PGMS) $(SAMPLE_PGMS) @@ -26,12 +28,12 @@ install.everything: install install.samples install.man install.samples: $(SAMPLE_PGMS) install /usr/bin/install -s -m 755 $(SAMPLE_PGMS) $(DESTDIR)/$(BINDIR) - /home/raldi/reddit/r2/r2/lib/contrib/discount-1.6.0/config.md $(DESTDIR)/$(MANDIR)/man1 + /home/raldi/reddit/r2/r2/lib/contrib/discount/config.md $(DESTDIR)/$(MANDIR)/man1 /usr/bin/install -m 444 theme.1 $(DESTDIR)/$(MANDIR)/man1 install.man: - /home/raldi/reddit/r2/r2/lib/contrib/discount-1.6.0/config.md $(DESTDIR)/$(MANDIR)/man3 - /usr/bin/install -m 444 mkd-functions.3 markdown.3 mkd-line.3 $(DESTDIR)/$(MANDIR)/man3 + /home/raldi/reddit/r2/r2/lib/contrib/discount/config.md $(DESTDIR)/$(MANDIR)/man3 + /usr/bin/install -m 444 $(MAN3PAGES) $(DESTDIR)/$(MANDIR)/man3 for x in mkd_line mkd_generateline; do \ ( echo '.\"' ; echo ".so man3/mkd-line.3" ) > $(DESTDIR)/$(MANDIR)/man3/$$x.3;\ done @@ -41,9 +43,9 @@ install.man: for x in mkd_compile mkd_css mkd_generatecss mkd_generatehtml mkd_cleanup mkd_doc_title mkd_doc_author mkd_doc_date; do \ ( echo '.\"' ; echo ".so man3/mkd-functions.3" ) > $(DESTDIR)/$(MANDIR)/man3/$$x.3; \ done - /home/raldi/reddit/r2/r2/lib/contrib/discount-1.6.0/config.md $(DESTDIR)/$(MANDIR)/man7 + /home/raldi/reddit/r2/r2/lib/contrib/discount/config.md $(DESTDIR)/$(MANDIR)/man7 /usr/bin/install -m 444 markdown.7 mkd-extensions.7 $(DESTDIR)/$(MANDIR)/man7 - /home/raldi/reddit/r2/r2/lib/contrib/discount-1.6.0/config.md $(DESTDIR)/$(MANDIR)/man1 + /home/raldi/reddit/r2/r2/lib/contrib/discount/config.md $(DESTDIR)/$(MANDIR)/man1 /usr/bin/install -m 444 markdown.1 $(DESTDIR)/$(MANDIR)/man1 install.everything: install install.man @@ -88,9 +90,22 @@ clean: distclean spotless: clean rm -f Makefile version.c markdown.1 config.cmd config.sub config.h config.mak config.log config.md -markdown.o: markdown.c config.h cstring.h markdown.h -generate.o: generate.c config.h cstring.h markdown.h -dumptree.o: dumptree.c cstring.h markdown.h -mkdio.o: mkdio.c mkdio.h cstring.h config.h -xmlpage.o: xmlpage.c mkdio.h cstring.h config.h -toc.o: toc.c mkdio.h cstring.h config.h +Csio.o: Csio.c cstring.h amalloc.h config.h markdown.h +amalloc.o: amalloc.c +basename.o: basename.c config.h cstring.h amalloc.h markdown.h +css.o: css.c config.h cstring.h amalloc.h markdown.h +docheader.o: docheader.c config.h cstring.h amalloc.h markdown.h +dumptree.o: dumptree.c markdown.h cstring.h amalloc.h config.h +emmatch.o: emmatch.c config.h cstring.h amalloc.h markdown.h +generate.o: generate.c config.h cstring.h amalloc.h markdown.h +main.o: main.c config.h amalloc.h +makepage.o: makepage.c +markdown.o: markdown.c config.h cstring.h amalloc.h markdown.h +mkd2html.o: mkd2html.c config.h mkdio.h cstring.h amalloc.h +mkdio.o: mkdio.c config.h cstring.h amalloc.h markdown.h +resource.o: resource.c config.h cstring.h amalloc.h markdown.h +theme.o: theme.c config.h mkdio.h cstring.h amalloc.h +toc.o: toc.c config.h cstring.h amalloc.h markdown.h +version.o: version.c config.h +xml.o: xml.c config.h cstring.h amalloc.h markdown.h +xmlpage.o: xmlpage.c config.h cstring.h amalloc.h markdown.h diff --git a/r2/r2/lib/contrib/discount-1.6.0/Makefile.in b/r2/r2/lib/contrib/discount/Makefile.in similarity index 67% rename from r2/r2/lib/contrib/discount-1.6.0/Makefile.in rename to r2/r2/lib/contrib/discount/Makefile.in index 9737e579ab..c4d5d562fd 100644 --- a/r2/r2/lib/contrib/discount-1.6.0/Makefile.in +++ b/r2/r2/lib/contrib/discount/Makefile.in @@ -13,7 +13,9 @@ SAMPLE_PGMS=mkd2html makepage MKDLIB=libmarkdown.a OBJS=mkdio.o markdown.o dumptree.o generate.o \ resource.o docheader.o version.o toc.o css.o \ - xml.o Csio.o xmlpage.o @AMALLOC@ + xml.o Csio.o xmlpage.o basename.o emmatch.o @AMALLOC@ + +MAN3PAGES=mkd-callbacks.3 mkd-functions.3 markdown.3 mkd-line.3 all: $(PGMS) $(SAMPLE_PGMS) @@ -31,7 +33,7 @@ install.samples: $(SAMPLE_PGMS) install install.man: @INSTALL_DIR@ $(DESTDIR)/$(MANDIR)/man3 - @INSTALL_DATA@ mkd-functions.3 markdown.3 mkd-line.3 $(DESTDIR)/$(MANDIR)/man3 + @INSTALL_DATA@ $(MAN3PAGES) $(DESTDIR)/$(MANDIR)/man3 for x in mkd_line mkd_generateline; do \ ( echo '.\"' ; echo ".so man3/mkd-line.3" ) > $(DESTDIR)/$(MANDIR)/man3/$$x.3;\ done @@ -88,9 +90,22 @@ clean: distclean spotless: clean rm -f @GENERATED_FILES@ @CONFIGURE_FILES@ -markdown.o: markdown.c config.h cstring.h markdown.h -generate.o: generate.c config.h cstring.h markdown.h -dumptree.o: dumptree.c cstring.h markdown.h -mkdio.o: mkdio.c mkdio.h cstring.h config.h -xmlpage.o: xmlpage.c mkdio.h cstring.h config.h -toc.o: toc.c mkdio.h cstring.h config.h +Csio.o: Csio.c cstring.h amalloc.h config.h markdown.h +amalloc.o: amalloc.c +basename.o: basename.c config.h cstring.h amalloc.h markdown.h +css.o: css.c config.h cstring.h amalloc.h markdown.h +docheader.o: docheader.c config.h cstring.h amalloc.h markdown.h +dumptree.o: dumptree.c markdown.h cstring.h amalloc.h config.h +emmatch.o: emmatch.c config.h cstring.h amalloc.h markdown.h +generate.o: generate.c config.h cstring.h amalloc.h markdown.h +main.o: main.c config.h amalloc.h +makepage.o: makepage.c +markdown.o: markdown.c config.h cstring.h amalloc.h markdown.h +mkd2html.o: mkd2html.c config.h mkdio.h cstring.h amalloc.h +mkdio.o: mkdio.c config.h cstring.h amalloc.h markdown.h +resource.o: resource.c config.h cstring.h amalloc.h markdown.h +theme.o: theme.c config.h mkdio.h cstring.h amalloc.h +toc.o: toc.c config.h cstring.h amalloc.h markdown.h +version.o: version.c config.h +xml.o: xml.c config.h cstring.h amalloc.h markdown.h +xmlpage.o: xmlpage.c config.h cstring.h amalloc.h markdown.h diff --git a/r2/r2/lib/contrib/discount-1.6.0/Plan9/README b/r2/r2/lib/contrib/discount/Plan9/README similarity index 100% rename from r2/r2/lib/contrib/discount-1.6.0/Plan9/README rename to r2/r2/lib/contrib/discount/Plan9/README diff --git a/r2/r2/lib/contrib/discount-1.6.0/Plan9/markdown.1 b/r2/r2/lib/contrib/discount/Plan9/markdown.1 similarity index 100% rename from r2/r2/lib/contrib/discount-1.6.0/Plan9/markdown.1 rename to r2/r2/lib/contrib/discount/Plan9/markdown.1 diff --git a/r2/r2/lib/contrib/discount-1.6.0/Plan9/markdown.2 b/r2/r2/lib/contrib/discount/Plan9/markdown.2 similarity index 100% rename from r2/r2/lib/contrib/discount-1.6.0/Plan9/markdown.2 rename to r2/r2/lib/contrib/discount/Plan9/markdown.2 diff --git a/r2/r2/lib/contrib/discount-1.6.0/Plan9/markdown.6 b/r2/r2/lib/contrib/discount/Plan9/markdown.6 similarity index 100% rename from r2/r2/lib/contrib/discount-1.6.0/Plan9/markdown.6 rename to r2/r2/lib/contrib/discount/Plan9/markdown.6 diff --git a/r2/r2/lib/contrib/discount-1.6.0/Plan9/mkfile b/r2/r2/lib/contrib/discount/Plan9/mkfile similarity index 100% rename from r2/r2/lib/contrib/discount-1.6.0/Plan9/mkfile rename to r2/r2/lib/contrib/discount/Plan9/mkfile diff --git a/r2/r2/lib/contrib/discount-1.6.0/README b/r2/r2/lib/contrib/discount/README similarity index 100% rename from r2/r2/lib/contrib/discount-1.6.0/README rename to r2/r2/lib/contrib/discount/README diff --git a/r2/r2/lib/contrib/discount/VERSION b/r2/r2/lib/contrib/discount/VERSION new file mode 100644 index 0000000000..9edc58bb1d --- /dev/null +++ b/r2/r2/lib/contrib/discount/VERSION @@ -0,0 +1 @@ +1.6.4 diff --git a/r2/r2/lib/contrib/discount-1.6.0/amalloc.c b/r2/r2/lib/contrib/discount/amalloc.c similarity index 100% rename from r2/r2/lib/contrib/discount-1.6.0/amalloc.c rename to r2/r2/lib/contrib/discount/amalloc.c diff --git a/r2/r2/lib/contrib/discount-1.6.0/amalloc.h b/r2/r2/lib/contrib/discount/amalloc.h similarity index 100% rename from r2/r2/lib/contrib/discount-1.6.0/amalloc.h rename to r2/r2/lib/contrib/discount/amalloc.h diff --git a/r2/r2/lib/contrib/discount/basename.c b/r2/r2/lib/contrib/discount/basename.c new file mode 100644 index 0000000000..237022a202 --- /dev/null +++ b/r2/r2/lib/contrib/discount/basename.c @@ -0,0 +1,43 @@ +/* + * mkdio -- markdown front end input functions + * + * Copyright (C) 2007 David L Parsons. + * The redistribution terms are provided in the COPYRIGHT file that must + * be distributed with this source code. + */ +#include "config.h" +#include +#include +#include + +#include "mkdio.h" +#include "cstring.h" +#include "amalloc.h" + +static char * +e_basename(const char *string, const int size, void *context) +{ + char *ret; + char *base = (char*)context; + + if ( base && string && (*string == '/') && (ret=malloc(strlen(base)+size+2)) ) { + strcpy(ret, base); + strncat(ret, string, size); + return ret; + } + return 0; +} + +static void +e_free(char *string, void *context) +{ + if ( string ) free(string); +} + +void +mkd_basename(MMIOT *document, char *base) +{ + mkd_e_url(document, e_basename); + mkd_e_data(document, base); + mkd_e_free(document, e_free); +} diff --git a/r2/r2/lib/contrib/discount-1.6.0/config.cmd b/r2/r2/lib/contrib/discount/config.cmd similarity index 100% rename from r2/r2/lib/contrib/discount-1.6.0/config.cmd rename to r2/r2/lib/contrib/discount/config.cmd diff --git a/r2/r2/lib/contrib/discount-1.6.0/config.h b/r2/r2/lib/contrib/discount/config.h similarity index 77% rename from r2/r2/lib/contrib/discount-1.6.0/config.h rename to r2/r2/lib/contrib/discount/config.h index 7ffdf5fabd..ec9f2e6ebd 100644 --- a/r2/r2/lib/contrib/discount-1.6.0/config.h +++ b/r2/r2/lib/contrib/discount/config.h @@ -1,5 +1,5 @@ /* - * configuration for markdown, generated Fri Jan 29 13:52:23 PST 2010 + * configuration for markdown, generated Mon May 17 13:43:31 PDT 2010 * by raldi@zork */ #ifndef __AC_MARKDOWN_D @@ -7,9 +7,6 @@ #define OS_LINUX 1 -#define DWORD unsigned long -#define WORD unsigned short -#define BYTE unsigned char #define HAVE_BASENAME 1 #define HAVE_LIBGEN_H 1 #define HAVE_PWD_H 1 diff --git a/r2/r2/lib/contrib/discount-1.6.0/config.log b/r2/r2/lib/contrib/discount/config.log similarity index 63% rename from r2/r2/lib/contrib/discount-1.6.0/config.log rename to r2/r2/lib/contrib/discount/config.log index 9b3c03dffd..1231807308 100644 --- a/r2/r2/lib/contrib/discount-1.6.0/config.log +++ b/r2/r2/lib/contrib/discount/config.log @@ -8,18 +8,19 @@ checking out the C compiler checking for "volatile" keyword checking for "const" keyword defining WORD & DWORD scalar types -/tmp/pd18169.c: In function 'main': -/tmp/pd18169.c:13: warning: incompatible implicit declaration of built-in function 'exit' -/tmp/ngc18169.c: In function 'main': -/tmp/ngc18169.c:5: warning: initialization makes pointer from integer without a cast -/tmp/ngc18169.c:6: warning: initialization makes pointer from integer without a cast +/tmp/pd26167.c: In function 'main': +/tmp/pd26167.c:29: warning: incompatible implicit declaration of built-in function 'exit' +/tmp/pd26167.c:16: warning: return type of 'main' is not 'int' +/tmp/ngc26167.c: In function 'main': +/tmp/ngc26167.c:5: warning: initialization makes pointer from integer without a cast +/tmp/ngc26167.c:6: warning: initialization makes pointer from integer without a cast looking for header libgen.h looking for header pwd.h looking for the getpwuid function looking for the srandom function looking for the bzero function -/tmp/ngc18169.c: In function 'main': -/tmp/ngc18169.c:4: warning: incompatible implicit declaration of built-in function 'bzero' +/tmp/ngc26167.c: In function 'main': +/tmp/ngc26167.c:4: warning: incompatible implicit declaration of built-in function 'bzero' looking for the random function looking for the strcasecmp function looking for the strncasecmp function diff --git a/r2/r2/lib/contrib/discount-1.6.0/config.mak b/r2/r2/lib/contrib/discount/config.mak similarity index 100% rename from r2/r2/lib/contrib/discount-1.6.0/config.mak rename to r2/r2/lib/contrib/discount/config.mak diff --git a/r2/r2/lib/contrib/discount/config.md b/r2/r2/lib/contrib/discount/config.md new file mode 100755 index 0000000000..7e9437fb90 --- /dev/null +++ b/r2/r2/lib/contrib/discount/config.md @@ -0,0 +1,5 @@ +#! /bin/sh +# script generated Mon May 17 13:43:31 PDT 2010 by configure.sh + +test -d "$1" || mkdir -p "$1" +exit 0 diff --git a/r2/r2/lib/contrib/discount-1.6.0/config.sub b/r2/r2/lib/contrib/discount/config.sub similarity index 76% rename from r2/r2/lib/contrib/discount-1.6.0/config.sub rename to r2/r2/lib/contrib/discount/config.sub index 7bd1f9a902..6fb1d363ea 100644 --- a/r2/r2/lib/contrib/discount-1.6.0/config.sub +++ b/r2/r2/lib/contrib/discount/config.sub @@ -3,10 +3,13 @@ s;@CPPFLAGS@;;g s;@INSTALL@;/usr/bin/install;g s;@INSTALL_PROGRAM@;/usr/bin/install -s -m 755;g s;@INSTALL_DATA@;/usr/bin/install -m 444;g -s;@INSTALL_DIR@;/home/raldi/reddit/r2/r2/lib/contrib/discount-1.6.0/config.md;g +s;@INSTALL_DIR@;/home/raldi/reddit/r2/r2/lib/contrib/discount/config.md;g s;@CC@;cc;g s;@AR@;/usr/bin/ar;g s;@RANLIB@;/usr/bin/ranlib;g +s:@DWORD@:unsigned long:g +s:@WORD@:unsigned short:g +s:@BYTE@:unsigned char:g s;@THEME@;;g s;@TABSTOP@;4;g s;@AMALLOC@;;g @@ -16,7 +19,7 @@ s;@CONFIGURE_FILES@;config.cmd config.sub config.h config.mak config.log config. s;@GENERATED_FILES@;Makefile version.c markdown.1;g s;@CFLAGS@;-g;g s;@LDFLAGS@;-g;g -s;@srcdir@;/home/raldi/reddit/r2/r2/lib/contrib/discount-1.6.0;g +s;@srcdir@;/home/raldi/reddit/r2/r2/lib/contrib/discount;g s;@prefix@;/usr/local;g s;@exedir@;/usr/local/bin;g s;@sbindir@;/usr/local/sbin;g diff --git a/r2/r2/lib/contrib/discount-1.6.0/configure.inc b/r2/r2/lib/contrib/discount/configure.inc similarity index 98% rename from r2/r2/lib/contrib/discount-1.6.0/configure.inc rename to r2/r2/lib/contrib/discount/configure.inc index 705128bda9..71e389211b 100755 --- a/r2/r2/lib/contrib/discount-1.6.0/configure.inc +++ b/r2/r2/lib/contrib/discount/configure.inc @@ -833,35 +833,56 @@ EOF AC_SCALAR_TYPES () { cat > /tmp/pd$$.c << EOF #include -main() +#include + +int pound_define = 1; + +void +say(char *w, char *v) +{ + printf(pound_define ? "#define %s %s\n" + : "s:@%s@:%s:g\n", w, v); +} + +void +main(argc, argv) +char **argv; { unsigned long v_long; unsigned int v_int; unsigned short v_short; + if ( argc > 1 && strcmp(argv[1], "sub") == 0 ) + pound_define = 0; + if (sizeof v_long == 4) - puts("#define DWORD unsigned long"); + say("DWORD", "unsigned long"); else if (sizeof v_int == 4) - puts("#define DWORD unsigned int"); + say("DWORD", "unsigned int"); else exit(1); if (sizeof v_int == 2) - puts("#define WORD unsigned int"); + say("WORD", "unsigned int"); else if (sizeof v_short == 2) - puts("#define WORD unsigned short"); + say("WORD", "unsigned short"); else exit(2); - puts("#define BYTE unsigned char"); + say("BYTE", "unsigned char"); exit(0); } EOF rc=1 LOGN "defining WORD & DWORD scalar types" if $AC_CC /tmp/pd$$.c -o /tmp/pd$$; then - if /tmp/pd$$ >> $__cwd/config.h; then - rc=0 - fi + case "$1" in + sub)if /tmp/pd$$ sub >> $__cwd/config.sub; then + rc=0 + fi;; + *) if /tmp/pd$$ >> $__cwd/config.h; then + rc=0 + fi ;; + esac fi case "$rc" in 0) TLOG "" ;; diff --git a/r2/r2/lib/contrib/discount-1.6.0/configure.sh b/r2/r2/lib/contrib/discount/configure.sh similarity index 99% rename from r2/r2/lib/contrib/discount-1.6.0/configure.sh rename to r2/r2/lib/contrib/discount/configure.sh index caf2c8a833..10582238e0 100755 --- a/r2/r2/lib/contrib/discount-1.6.0/configure.sh +++ b/r2/r2/lib/contrib/discount/configure.sh @@ -63,7 +63,7 @@ AC_PROG ranlib AC_C_VOLATILE AC_C_CONST -AC_SCALAR_TYPES +AC_SCALAR_TYPES sub AC_CHECK_BASENAME AC_CHECK_HEADERS sys/types.h pwd.h && AC_CHECK_FUNCS getpwuid diff --git a/r2/r2/lib/contrib/discount-1.6.0/css.c b/r2/r2/lib/contrib/discount/css.c similarity index 100% rename from r2/r2/lib/contrib/discount-1.6.0/css.c rename to r2/r2/lib/contrib/discount/css.c diff --git a/r2/r2/lib/contrib/discount-1.6.0/cstring.h b/r2/r2/lib/contrib/discount/cstring.h similarity index 100% rename from r2/r2/lib/contrib/discount-1.6.0/cstring.h rename to r2/r2/lib/contrib/discount/cstring.h diff --git a/r2/r2/lib/contrib/discount-1.6.0/docheader.c b/r2/r2/lib/contrib/discount/docheader.c similarity index 100% rename from r2/r2/lib/contrib/discount-1.6.0/docheader.c rename to r2/r2/lib/contrib/discount/docheader.c diff --git a/r2/r2/lib/contrib/discount-1.6.0/dumptree.c b/r2/r2/lib/contrib/discount/dumptree.c old mode 100755 new mode 100644 similarity index 100% rename from r2/r2/lib/contrib/discount-1.6.0/dumptree.c rename to r2/r2/lib/contrib/discount/dumptree.c diff --git a/r2/r2/lib/contrib/discount/emmatch.c b/r2/r2/lib/contrib/discount/emmatch.c new file mode 100644 index 0000000000..896ceaccc4 --- /dev/null +++ b/r2/r2/lib/contrib/discount/emmatch.c @@ -0,0 +1,188 @@ +/* markdown: a C implementation of John Gruber's Markdown markup language. + * + * Copyright (C) 2010 David L Parsons. + * The redistribution terms are provided in the COPYRIGHT file that must + * be distributed with this source code. + */ +#include +#include +#include +#include +#include +#include + +#include "config.h" + +#include "cstring.h" +#include "markdown.h" +#include "amalloc.h" + + +/* emmatch: the emphasis mangler that's run after a block + * of html has been generated. + * + * It should create MarkdownTest_1.0 (and _1.0.3) + * compatable emphasis for non-pathological cases + * and it should fail in a standards-compliant way + * when someone attempts to feed it junk. + * + * Emmatching is done after the input has been + * processed into a STRING (f->Q) of text and + * emphasis blocks. After ___mkd_emblock() finishes, + * it truncates f->Q and leaves the rendered paragraph + * if f->out. + */ + + +/* empair() -- find the NEAREST matching emphasis token (or + * subtoken of a 3+ long emphasis token. + */ +static int +empair(MMIOT *f, int first, int last, int match) +{ + + int i; + block *begin, *p; + + begin = &T(f->Q)[first]; + + for (i=first+1; i <= last; i++) { + p = &T(f->Q)[i]; + + if ( (p->b_type != bTEXT) && (p->b_count <= 0) ) + continue; /* break? */ + + if ( p->b_type == begin->b_type ) { + if ( p->b_count == match ) /* exact match */ + return i; + + if ( p->b_count > 2 ) /* fuzzy match */ + return i; + } + } + return 0; +} /* empair */ + + +/* emfill() -- if an emphasis token has leftover stars or underscores, + * convert them back into character and append them to b_text. + */ +static void +emfill(block *p) +{ + int j; + + if ( p->b_type == bTEXT ) + return; + + for (j=0; j < p->b_count; j++) + EXPAND(p->b_text) = p->b_char; + p->b_count = 0; +} /* emfill */ + + +static void +emclose(MMIOT *f, int first, int last) +{ + int j; + + for (j=first+1; jQ)[j]); +} + + +static struct emtags { + char open[10]; + char close[10]; + int size; +} emtags[] = { { "" , "", 5 }, { "", "", 9 } }; + + +static void emblock(MMIOT*,int,int); + + +/* emmatch() -- match emphasis for a single emphasis token. + */ +static void +emmatch(MMIOT *f, int first, int last) +{ + block *start = &T(f->Q)[first]; + int e, e2, match; + + switch (start->b_count) { + case 2: if ( e = empair(f,first,last,match=2) ) + break; + case 1: e = empair(f,first,last,match=1); + break; + case 0: return; + default: + e = empair(f,first,last,1); + e2= empair(f,first,last,2); + + if ( e2 >= e ) { + e = e2; + match = 2; + } + else + match = 1; + break; + } + + if ( e ) { + /* if we found emphasis to match, match it, recursively call + * emblock to match emphasis inside the new html block, add + * the emphasis markers for the block, then (tail) recursively + * call ourself to match any remaining emphasis on this token. + */ + block *end = &T(f->Q)[e]; + + end->b_count -= match; + start->b_count -= match; + + emblock(f, first, e); + + PREFIX(start->b_text, emtags[match-1].open, emtags[match-1].size-1); + SUFFIX(end->b_post, emtags[match-1].close, emtags[match-1].size); + + emmatch(f, first, last); + } +} /* emmatch */ + + +/* emblock() -- walk a blocklist, attempting to match emphasis + */ +static void +emblock(MMIOT *f, int first, int last) +{ + int i; + + for ( i = first; i <= last; i++ ) + if ( T(f->Q)[i].b_type != bTEXT ) + emmatch(f, i, last); + emclose(f, first, last); +} /* emblock */ + + +/* ___mkd_emblock() -- emblock a string of blocks, then concatinate the + * resulting text onto f->out. + */ +void +___mkd_emblock(MMIOT *f) +{ + int i; + block *p; + + emblock(f, 0, S(f->Q)-1); + + for (i=0; i < S(f->Q); i++) { + p = &T(f->Q)[i]; + emfill(p); + + if ( S(p->b_post) ) { SUFFIX(f->out, T(p->b_post), S(p->b_post)); + DELETE(p->b_post); } + if ( S(p->b_text) ) { SUFFIX(f->out, T(p->b_text), S(p->b_text)); + DELETE(p->b_text); } + } + + S(f->Q) = 0; +} /* ___mkd_emblock */ diff --git a/r2/r2/lib/contrib/discount-1.6.0/generate.c b/r2/r2/lib/contrib/discount/generate.c similarity index 83% rename from r2/r2/lib/contrib/discount-1.6.0/generate.c rename to r2/r2/lib/contrib/discount/generate.c index 64428d724c..075a203bb0 100644 --- a/r2/r2/lib/contrib/discount-1.6.0/generate.c +++ b/r2/r2/lib/contrib/discount/generate.c @@ -21,8 +21,6 @@ typedef int (*stfu)(const void*,const void*); /* forward declarations */ -static int iscodeblock(MMIOT*); -static void code(int, MMIOT*); static void text(MMIOT *f); static Paragraph *display(Paragraph*, MMIOT*); @@ -166,6 +164,16 @@ Qprintf(MMIOT *f, char *fmt, ...) } +/* Qcopy() + */ +static void +Qcopy(int count, MMIOT *f) +{ + while ( count-- > 0 ) + Qchar(pull(f), f); +} + + /* Qem() */ static void @@ -182,118 +190,6 @@ Qem(MMIOT *f, char c, int count) } -/* empair() - */ -static int -empair(MMIOT *f, int go, int level) -{ - - int i; - block *begin, *p; - - begin = &T(f->Q)[go]; - for (i=go+1; i < S(f->Q); i++) { - p = &T(f->Q)[i]; - - if ( (p->b_type != bTEXT) && (p->b_count <= 0) ) - break; - - if ( p->b_type == begin->b_type ) { - if ( p->b_count == level ) /* exact match */ - return i-go; - - if ( p->b_count > 2 ) /* fuzzy match */ - return i-go; - } - } - return EOF; -} - - - -static struct emtags { - char open[10]; - char close[10]; - int size; -} emtags[] = { { "" , "", 5 }, { "", "", 9 } }; - - -static void -emclose(Cstring *s, int level) -{ - PREFIX(*s, emtags[level-1].close, emtags[level-1].size); -} - - -static void -emopen(Cstring *s, int level) -{ - SUFFIX(*s, emtags[level-1].open, emtags[level-1].size-1); -} - - -/* emmatch() - */ -static void -emmatch(MMIOT *f, int go) -{ - block *start = &T(f->Q)[go], *end; - int e, e2, i, match; - - while ( start->b_count ) { - switch (start->b_count) { - case 2: e = empair(f,go,match=2); - if ( e != EOF ) break; - case 1: e = empair(f,go,match=1); break; - default: - e = empair(f,go,1); - e2= empair(f,go,2); - - if ( e == EOF || ((e2 != EOF) && (e2 >= e)) ) { - e = e2; - match = 2; - } - else - match = 1; - } - if ( e != EOF ) { - end = &T(f->Q)[go+e]; - emclose(&end->b_post, match); - emopen(&start->b_text, match); - end->b_count -= match; - } - else { - for (i=0; i < match; i++) - EXPAND(start->b_text) = start->b_char; - } - - start->b_count -= match; - } -} - - -/* ___mkd_emblock() - */ -void -___mkd_emblock(MMIOT *f) -{ - int i; - block *p; - - for (i=0; i < S(f->Q); i++) { - p = &T(f->Q)[i]; - - if ( p->b_type != bTEXT ) emmatch(f, i); - - if ( S(p->b_post) ) { SUFFIX(f->out, T(p->b_post), S(p->b_post)); - DELETE(p->b_post); } - if ( S(p->b_text) ) { SUFFIX(f->out, T(p->b_text), S(p->b_text)); - DELETE(p->b_text); } - } - S(f->Q) = 0; -} - - /* generate html from a markup fragment */ void @@ -304,7 +200,7 @@ ___mkd_reparse(char *bfr, int size, int flags, MMIOT *f) ___mkd_initmmiot(&sub, f->footnotes); sub.flags = f->flags | flags; - sub.base = f->base; + sub.cb = f->cb; push(bfr, size, &sub); EXPAND(sub.in) = 0; @@ -345,6 +241,8 @@ puturl(char *s, int size, MMIOT *f, int display) Qstring("%22", f); else if ( isalnum(c) || ispunct(c) || (display && isspace(c)) ) Qchar(c, f); + else if ( c == 003 ) /* untokenize ^C */ + Qstring(" ", f); else Qprintf(f, "%%%02X", c); } @@ -512,27 +410,28 @@ linkyurl(MMIOT *f, int image, Footnote *p) /* prefixes for */ -static struct { +static struct _protocol { char *name; int nlen; } protocol[] = { #define _aprotocol(x) { x, (sizeof x)-1 } - _aprotocol( "http://" ), _aprotocol( "https://" ), - _aprotocol( "ftp://" ), + _aprotocol( "http://" ), _aprotocol( "news://" ), + _aprotocol( "ftp://" ), #undef _aprotocol }; #define NRPROTOCOLS (sizeof protocol / sizeof protocol[0]) static int -isautoprefix(char *text) +isautoprefix(char *text, int size) { int i; + struct _protocol *p; - for (i=0; i < NRPROTOCOLS; i++) - if ( strncasecmp(text, protocol[i].name, protocol[i].nlen) == 0 ) + for (i=0, p=protocol; i < NRPROTOCOLS; i++, p++) + if ( (size >= p->nlen) && strncasecmp(text, p->name, p->nlen) == 0 ) return 1; return 0; } @@ -569,9 +468,10 @@ static linkytype linkt = { 0, 0, "", "", 0, IS_URL }, - { "class:", 6, "", "", 0, 0 }, { "raw:", 4, 0, 0, 0, 0, 0, DENY_HTML, 0 }, + { "lang:", 5, "", "", 0, 0 }, { "abbr:", 5, "", "", 0, 0 }, + { "class:", 6, "", "", 0, 0 }, } ; #define NR(x) (sizeof x / sizeof x[0]) @@ -584,8 +484,7 @@ pseudo(Cstring t) int i; linkytype *r; - for ( i=0; i < NR(specials); i++ ) { - r = &specials[i]; + for ( i=0, r=specials; i < NR(specials); i++,r++ ) { if ( (S(t) > r->szpat) && (strncasecmp(T(t), r->pat, r->szpat) == 0) ) return r; } @@ -593,13 +492,42 @@ pseudo(Cstring t) } +/* print out the start of an `img' or `a' tag, applying callbacks as needed. + */ +static void +printlinkyref(MMIOT *f, linkytype *tag, char *link, int size) +{ + char *edit; + + Qstring(tag->link_pfx, f); + + if ( tag->kind & IS_URL ) { + if ( f->cb->e_url && (edit = (*f->cb->e_url)(link, size, f->cb->e_data)) ) { + puturl(edit, strlen(edit), f, 0); + if ( f->cb->e_free ) (*f->cb->e_free)(edit, f->cb->e_data); + } + else + puturl(link + tag->szpat, size - tag->szpat, f, 0); + } + else + ___mkd_reparse(link + tag->szpat, size - tag->szpat, INSIDE_TAG, f); + + Qstring(tag->link_sfx, f); + + if ( f->cb->e_flags && (edit = (*f->cb->e_flags)(link, size, f->cb->e_data)) ) { + Qchar(' ', f); + Qstring(edit, f); + if ( f->cb->e_free ) (*f->cb->e_free)(edit, f->cb->e_data); + } +} /* printlinkyref */ + + /* print out a linky (or fail if it's Not Allowed) */ static int linkyformat(MMIOT *f, Cstring text, int image, Footnote *ref) { linkytype *tag; - char *edit; if ( image ) tag = &imaget; @@ -609,11 +537,11 @@ linkyformat(MMIOT *f, Cstring text, int image, Footnote *ref) } else if ( (f->flags & SAFELINK) && T(ref->link) && (T(ref->link)[0] != '/') - && !isautoprefix(T(ref->link)) ) + && !isautoprefix(T(ref->link), S(ref->link)) ) /* if SAFELINK, only accept links that are local or * a well-known protocol */ - return 0; + return 0; else tag = &linkt; @@ -621,33 +549,11 @@ linkyformat(MMIOT *f, Cstring text, int image, Footnote *ref) return 0; if ( tag->link_pfx ) { - Qstring(tag->link_pfx, f); - - if ( tag->kind & IS_URL ) { - if ( f->e_url && (edit = (*f->e_url)(T(ref->link), S(ref->link), f->e_context)) ) { - puturl(edit, strlen(edit), f, 0); - if ( f->e_free ) (*f->e_free)(edit, f->e_context); - } - else { - if ( f->base && T(ref->link) && (T(ref->link)[tag->szpat] == '/') ) - puturl(f->base, strlen(f->base), f, 0); - puturl(T(ref->link) + tag->szpat, S(ref->link) - tag->szpat, f, 0); - } - } - else - ___mkd_reparse(T(ref->link) + tag->szpat, S(ref->link) - tag->szpat, INSIDE_TAG, f); - - Qstring(tag->link_sfx, f); + printlinkyref(f, tag, T(ref->link), S(ref->link)); - if ( f->e_flags && (edit = (*f->e_flags)(T(ref->link), S(ref->link), f->e_context)) ) { - Qchar(' ', f); - Qstring(edit, f); - if ( f->e_free ) (*f->e_free)(edit, f->e_context); - } - - if ( tag->WxH) { - if ( ref->height) Qprintf(f," height=\"%d\"", ref->height); - if ( ref->width) Qprintf(f, " width=\"%d\"", ref->width); + if ( tag->WxH ) { + if ( ref->height ) Qprintf(f," height=\"%d\"", ref->height); + if ( ref->width ) Qprintf(f, " width=\"%d\"", ref->width); } if ( S(ref->title) ) { @@ -755,6 +661,89 @@ mangle(char *s, int len, MMIOT *f) } +/* nrticks() -- count up a row of tick marks + */ +static int +nrticks(int offset, MMIOT *f) +{ + int tick = 0; + + while ( peek(f, offset+tick) == '`' ) tick++; + + return tick; +} /* nrticks */ + + +/* matchticks() -- match a certain # of ticks, and if that fails + * match the largest subset of those ticks. + * + * if a subset was matched, modify the passed in + * # of ticks so that the caller (text()) can + * appropriately process the horrible thing. + */ +static int +matchticks(MMIOT *f, int *ticks) +{ + int size, tick, c; + int subsize=0, subtick=0; + + for (size = *ticks; (c=peek(f,size)) != EOF; ) { + if ( c == '`' ) + if ( (tick=nrticks(size,f)) == *ticks ) + return size; + else { + if ( tick > subtick ) { + subsize = size; + subtick = tick; + } + size += tick; + } + else + size++; + } + if ( subsize ) { + *ticks = subtick; + return subsize; + } + return 0; + +} /* matchticks */ + + +/* code() -- write a string out as code. The only characters that have + * special meaning in a code block are * `<' and `&' , which + * are /always/ expanded to < and & + */ +static void +code(MMIOT *f, char *s, int length) +{ + int i,c; + + for ( i=0; i < length; i++ ) + if ( (c = s[i]) == 003) /* ^C: expand back to 2 spaces */ + Qstring(" ", f); + else + cputc(c, f); +} /* code */ + + +/* codespan() -- write out a chunk of text as code, trimming one + * space off the front and/or back as appropriate. + */ +static void +codespan(MMIOT *f, int size) +{ + int i=0, c; + + if ( size > 1 && peek(f, size-1) == ' ' ) --size; + if ( peek(f,i) == ' ' ) ++i, --size; + + Qstring("", f); + code(f, cursor(f)+(i-1), size); + Qstring("", f); +} /* codespan */ + + /* before letting a tag through, validate against * DENY_A and DENY_IMG */ @@ -839,23 +828,9 @@ process_possible_link(MMIOT *f, int size) Qstring("", f); return 1; } - else if ( isautoprefix(text) ) { - char *edit; - Qstring("e_url && (edit = (*f->e_url)(text, size, f->e_context)) ) { - puturl(edit, strlen(edit), f, 0); - if ( f->e_free ) (*f->e_free)(edit, f->e_context); - } - else - puturl(text,size,f, 0); - if ( f->e_flags && (edit = (*f->e_flags)(text, size, f->e_context)) ) { - Qstring("\" ", f); - Qstring(edit, f); - if ( f->e_free ) (*f->e_free)(edit, f->e_context); - Qchar('>', f); - } - else - Qstring("\">", f); + else if ( isautoprefix(text, size) ) { + printlinkyref(f, &linkt, text, size); + Qchar('>', f); puturl(text,size,f, 1); Qstring("", f); return 1; @@ -1010,6 +985,11 @@ static struct smarties { } smarties[] = { { '\'', "'s>", "rsquo", 0 }, { '\'', "'t>", "rsquo", 0 }, + { '\'', "'re>", "rsquo", 0 }, + { '\'', "'ll>", "rsquo", 0 }, + { '\'', "'ve>", "rsquo", 0 }, + { '\'', "'m>", "rsquo", 0 }, + { '\'', "'d>", "rsquo", 0 }, { '-', "--", "mdash", 1 }, { '-', "<->", "ndash", 0 }, { '.', "...", "hellip", 2 }, @@ -1102,7 +1082,7 @@ text(MMIOT *f) switch (c) { case 0: break; - case 3: Qstring("
", f); + case 3: Qstring(tag_text(f) ? " " : "
", f); break; case '>': if ( tag_text(f) ) @@ -1155,16 +1135,13 @@ text(MMIOT *f) } #endif case '*': -#if RELAXED_EMPHASIS /* Underscores & stars don't count if they're out in the middle * of whitespace */ - if ( !(f->flags & STRICT) && isthisspace(f,-1) - && isthisspace(f,1) ) { + if ( isthisspace(f,-1) && isthisspace(f,1) ) { Qchar(c, f); break; } /* else fall into the regular old emphasis case */ -#endif if ( tag_text(f) ) Qchar(c, f); else { @@ -1174,17 +1151,20 @@ text(MMIOT *f) } break; - case '`': if ( tag_text(f) || !iscodeblock(f) ) + case '`': if ( tag_text(f) ) Qchar(c, f); else { - Qstring("", f); - if ( peek(f, 1) == '`' ) { - pull(f); - code(2, f); + int size, tick = nrticks(0, f); + + if ( size = matchticks(f, &tick) ) { + shift(f, tick); + codespan(f, size-tick); + shift(f, size-1); + } + else { + Qchar(c, f); + Qcopy(tick-1, f); } - else - code(1, f); - Qstring("", f); } break; @@ -1230,78 +1210,6 @@ text(MMIOT *f) } /* text */ -static int -iscodeblock(MMIOT *f) -{ - int i=1, single = 1, c; - - if ( peek(f,i) == '`' ) { - single=0; - i++; - } - while ( (c=peek(f,i)) != EOF ) { - if ( (c == '`') && (single || peek(f,i+1) == '`') ) - return 1; - else if ( c == '\\' ) - i++; - i++; - } - return 0; - -} - -static int -endofcode(int escape, int offset, MMIOT *f) -{ - switch (escape) { - case 2: if ( peek(f, offset+1) == '`' ) { - shift(f,1); - case 1: shift(f,offset); - return 1; - } - default:return 0; - } -} - - -/* the only characters that have special meaning in a code block are - * `<' and `&' , which are /always/ expanded to < and & - */ -static void -code(int escape, MMIOT *f) -{ - int c; - - if ( escape && (peek(f,1) == ' ') ) - shift(f,1); - - while ( (c = pull(f)) != EOF ) { - switch (c) { - case ' ': if ( peek(f,1) == '`' && endofcode(escape, 1, f) ) - return; - Qchar(c, f); - break; - - case '`': if ( endofcode(escape, 0, f) ) - return; - Qchar(c, f); - break; - - case '\\': cputc(c, f); - if ( peek(f,1) == '>' || (c = pull(f)) == EOF ) - break; - - case 003: /* ^C; expand back to spaces */ - Qstring(" ", f); - break; - - default: cputc(c, f); - break; - } - } -} /* code */ - - /* print a header block */ static void @@ -1360,6 +1268,7 @@ splat(Line *p, char *block, Istring align, int force, MMIOT *f) return colno; } + static int printtable(Paragraph *pp, MMIOT *f) { @@ -1456,19 +1365,18 @@ printcode(Line *t, MMIOT *f) { int blanks; - for ( blanks = 0; t ; t = t->next ) + Qstring("
", f);
+    for ( blanks = 0; t ; t = t->next ) {
 	if ( S(t->text) > t->dle ) {
 	    while ( blanks ) {
-		push("\n", 1, f);
+		Qchar('\n', f);
 		--blanks;
 	    }
-	    push(T(t->text), S(t->text), f);
-	    push("\n", 1, f);
+	    code(f, T(t->text), S(t->text));
+	    Qchar('\n', f);
 	}
 	else blanks++;
-
-    Qstring("
", f);
-    code(0, f);
+    }
     Qstring("
", f); } diff --git a/r2/r2/lib/contrib/discount-1.6.0/main.c b/r2/r2/lib/contrib/discount/main.c similarity index 93% rename from r2/r2/lib/contrib/discount-1.6.0/main.c rename to r2/r2/lib/contrib/discount/main.c index 4a50efe1bb..3d6e502603 100644 --- a/r2/r2/lib/contrib/discount-1.6.0/main.c +++ b/r2/r2/lib/contrib/discount/main.c @@ -99,9 +99,9 @@ set(int *flags, char *optionstring) char * -e_flags(char *text, int size, char *context) +e_flags(const char *text, const int size, void *context) { - return context; + return (char*)context; } @@ -127,7 +127,7 @@ main(int argc, char **argv) pgm = basename(argv[0]); opterr = 1; - while ( (opt=getopt(argc, argv, "b:df:F:o:s:t:TVZ:")) != EOF ) { + while ( (opt=getopt(argc, argv, "b:df:E:F:o:s:t:TV")) != EOF ) { switch (opt) { case 'b': urlbase = optarg; break; @@ -135,6 +135,8 @@ main(int argc, char **argv) break; case 'V': printf("%s: discount %s\n", pgm, markdown_version); exit(0); + case 'E': urlflags = optarg; + break; case 'F': flags = strtol(optarg, 0, 0); break; case 'f': set(&flags, optarg); @@ -155,8 +157,6 @@ main(int argc, char **argv) exit(1); } break; - case 'Z': urlflags = optarg; - break; default: fprintf(stderr, "usage: %s [-dTV] [-b url-base]" " [-F bitmap] [-f {+-}flags]" " [-o ofile] [-s text]" @@ -188,16 +188,16 @@ main(int argc, char **argv) } if ( urlbase ) mkd_basename(doc, urlbase); + if ( urlflags ) { + mkd_e_data(doc, urlflags); + mkd_e_flags(doc, e_flags); + } if ( debug ) rc = mkd_dump(doc, stdout, 0, argc ? basename(argv[0]) : "stdin"); else { rc = 1; if ( mkd_compile(doc, flags) ) { - if ( urlflags ) { - mkd_e_context(doc, urlflags); - mkd_e_flags(doc, e_flags); - } rc = 0; if ( toc ) mkd_generatetoc(doc, stdout); diff --git a/r2/r2/lib/contrib/discount-1.6.0/makepage.c b/r2/r2/lib/contrib/discount/makepage.c similarity index 100% rename from r2/r2/lib/contrib/discount-1.6.0/makepage.c rename to r2/r2/lib/contrib/discount/makepage.c diff --git a/r2/r2/lib/contrib/discount-1.6.0/markdown.1 b/r2/r2/lib/contrib/discount/markdown.1 similarity index 100% rename from r2/r2/lib/contrib/discount-1.6.0/markdown.1 rename to r2/r2/lib/contrib/discount/markdown.1 diff --git a/r2/r2/lib/contrib/discount-1.6.0/markdown.1.in b/r2/r2/lib/contrib/discount/markdown.1.in similarity index 100% rename from r2/r2/lib/contrib/discount-1.6.0/markdown.1.in rename to r2/r2/lib/contrib/discount/markdown.1.in diff --git a/r2/r2/lib/contrib/discount-1.6.0/markdown.3 b/r2/r2/lib/contrib/discount/markdown.3 similarity index 99% rename from r2/r2/lib/contrib/discount-1.6.0/markdown.3 rename to r2/r2/lib/contrib/discount/markdown.3 index 8022f80503..4fcd2da141 100644 --- a/r2/r2/lib/contrib/discount-1.6.0/markdown.3 +++ b/r2/r2/lib/contrib/discount/markdown.3 @@ -103,6 +103,7 @@ and functions return a MMIOT* on success, null on failure. .Sh SEE ALSO .Xr markdown 1 , +.Xr mkd-callbacks 3 , .Xr mkd-functions 3 , .Xr mkd-line 3 , .Xr markdown 7 , diff --git a/r2/r2/lib/contrib/discount-1.6.0/markdown.7 b/r2/r2/lib/contrib/discount/markdown.7 similarity index 99% rename from r2/r2/lib/contrib/discount-1.6.0/markdown.7 rename to r2/r2/lib/contrib/discount/markdown.7 index be844da017..7c76a2c486 100644 --- a/r2/r2/lib/contrib/discount-1.6.0/markdown.7 +++ b/r2/r2/lib/contrib/discount/markdown.7 @@ -1001,6 +1001,7 @@ John Gruber .Sh SEE ALSO .Xr markdown 1 , .Xr markdown 3 , +.Xr mkd-callbacks 3 , .Xr mkd-functions 3 , .Xr mkd-extensions 7 . .Pp diff --git a/r2/r2/lib/contrib/discount-1.6.0/markdown.c b/r2/r2/lib/contrib/discount/markdown.c similarity index 97% rename from r2/r2/lib/contrib/discount-1.6.0/markdown.c rename to r2/r2/lib/contrib/discount/markdown.c index e021fb770b..95b402cd8b 100644 --- a/r2/r2/lib/contrib/discount-1.6.0/markdown.c +++ b/r2/r2/lib/contrib/discount/markdown.c @@ -171,6 +171,8 @@ typedef struct _flo { int i; } FLO; +#define floindex(x) (x.i) + static int flogetc(FLO *f) @@ -186,6 +188,22 @@ flogetc(FLO *f) } +static void +splitline(Line *t, int cutpoint) +{ + if ( t && (cutpoint < S(t->text)) ) { + Line *tmp = calloc(1, sizeof *tmp); + + tmp->next = t->next; + t->next = tmp; + + tmp->dle = t->dle; + SUFFIX(tmp->text, T(t->text)+cutpoint, S(t->text)-cutpoint); + S(t->text) = cutpoint; + } +} + + static Line * htmlblock(Paragraph *p, struct kw *tag) { @@ -232,6 +250,7 @@ htmlblock(Paragraph *p, struct kw *tag) } if ( !f.t ) return 0; + splitline(f.t, floindex(f)); ret = f.t->next; f.t->next = 0; return ret; @@ -248,9 +267,11 @@ static Line * comment(Paragraph *p) { Line *t, *ret; + char *end; for ( t = p->text; t ; t = t->next) { - if ( strstr(T(t->text), "-->") ) { + if ( end = strstr(T(t->text), "-->") ) { + splitline(t, 3 + (end - T(t->text)) ); ret = t->next; t->next = 0; return ret; @@ -305,8 +326,8 @@ isfootnote(Line *t) for ( ++i; i < S(t->text) ; ++i ) { if ( T(t->text)[i] == '[' ) return 0; - else if ( T(t->text)[i] == ']' && T(t->text)[i+1] == ':' ) - return 1; + else if ( T(t->text)[i] == ']' ) + return ( T(t->text)[i+1] == ':' ) ; } return 0; } @@ -487,7 +508,8 @@ headerblock(Paragraph *pp, int htyp) * the leading and trailing `#`'s */ - for (i=0; (T(p->text)[i] == T(p->text)[0]) && (i < S(p->text)-1); i++) + for (i=0; (T(p->text)[i] == T(p->text)[0]) && (i < S(p->text)-1) + && (i < 6); i++) ; pp->hnumber = i; @@ -1083,8 +1105,8 @@ mkd_compile(Document *doc, int flags) doc->compiled = 1; memset(doc->ctx, 0, sizeof(MMIOT) ); - doc->ctx->flags = flags & USER_FLAGS; - doc->ctx->base = doc->base; + doc->ctx->cb = &(doc->cb); + doc->ctx->flags = flags & USER_FLAGS; CREATE(doc->ctx->in); doc->ctx->footnotes = malloc(sizeof doc->ctx->footnotes[0]); CREATE(*doc->ctx->footnotes); diff --git a/r2/r2/lib/contrib/discount-1.6.0/markdown.h b/r2/r2/lib/contrib/discount/markdown.h similarity index 90% rename from r2/r2/lib/contrib/discount-1.6.0/markdown.h rename to r2/r2/lib/contrib/discount/markdown.h index 1999152add..26d9269fda 100644 --- a/r2/r2/lib/contrib/discount-1.6.0/markdown.h +++ b/r2/r2/lib/contrib/discount/markdown.h @@ -56,11 +56,20 @@ typedef struct block { typedef STRING(block) Qblock; +typedef char* (*mkd_callback_t)(const char*, const int, void*); +typedef void (*mkd_free_t)(char*, void*); + +typedef struct callback_data { + void *e_data; /* private data for callbacks */ + mkd_callback_t e_url; /* url edit callback */ + mkd_callback_t e_flags; /* extra href flags callback */ + mkd_free_t e_free; /* edit/flags callback memory deallocator */ +} Callback_data; + + /* a magic markdown io thing holds all the data structures needed to * do the backend processing of a markdown document */ -typedef char* (*e_func)(const char*, const int, void*); - typedef struct mmiot { Cstring out; Cstring in; @@ -83,10 +92,7 @@ typedef struct mmiot { #define SAFELINK 0x8000 #define USER_FLAGS 0xFCFF #define EMBEDDED DENY_A|DENY_IMG|NO_PSEUDO_PROTO|CDATA_OUTPUT - char *base; - void *e_context; - e_func e_url, e_flags; - void (*e_free)(void*,void*); + Callback_data *cb; } MMIOT; @@ -105,7 +111,7 @@ typedef struct document { int html; /* set after (internal) htmlify() */ int tabstop; /* for properly expanding tabs (ick) */ MMIOT *ctx; /* backend buffers, flags, and structures */ - char *base; /* url basename for url fragments */ + Callback_data cb; /* callback functions & private data */ } Document; diff --git a/r2/r2/lib/contrib/discount/mkd-callbacks.3 b/r2/r2/lib/contrib/discount/mkd-callbacks.3 new file mode 100644 index 0000000000..be14c2a5d0 --- /dev/null +++ b/r2/r2/lib/contrib/discount/mkd-callbacks.3 @@ -0,0 +1,71 @@ +.\" +.Dd January 18, 2008 +.Dt MKD_CALLBACKS 3 +.Os Mastodon +.Sh NAME +.Nm mkd_callbacks +.Nd functions that modify link targets +.Sh LIBRARY +Markdown +.Pq libmarkdown , -lmarkdown +.Sh SYNOPSIS +.Fd #include +.Ft char* +.Fn (*mkd_callback_t) "const char*" "const int" "void*" +.Ft void +.Fn (*mkd_free_t) "char *" "void*" +.Ft void +.Fn mkd_e_url "MMIOT *document" "mkd_callback_t edit" +.Ft void +.Fn mkd_e_flags "MMIOT *document" "mkd_callback_t edit" +.Ft void +.Fn mkd_e_free "MMIOT *document" "mkd_free_t dealloc" +.Ft void +.Fn mkd_e_data "MMIOT *document" "void *data" +.Sh DESCRIPTION +.Pp +.Nm Discount +provides a small set of data access functions to let a +library user modify the targets given in a `[]' link, and to +add additional flags to the generated link. +.Pp +The data access functions are passed a character pointer to +the url being generated, the size of the url, and a data pointer +pointing to a user data area (set by the +.Fn mkd_e_data +function.) After the callback function is called (either +.Fn mkd_e_url +or +.Fn mkd_e_flags ) +the data freeing function (if supplied) is called and passed the +character pointer and user data pointer. +.Sh EXAMPLE +The +.Fn mkd_basename +function (in the module basename.c) is implemented by means of +mkd callbacks; it modifies urls that start with a `/' so that +they begin with a user-supplied url base by allocating a new +string and filling it with the base + the url. Discount plugs +that url in in place of the original, then calls the basename +free function (it only does this when +.Fn mkd_e_url +or +.Fn mkd_e_flags +returns nonzero) to deallocate this memory. +.Pp +Note that only one level of callbacks are supported; if you +wish to do multiple callbacks, you need to write your own +code to handle them all. +.Sh SEE ALSO +.Xr markdown 1 , +.Xr markdown 3 , +.Xr mkd-line 3 , +.Xr markdown 7 , +.Xr mkd-extensions 7 , +.Xr mmap 2 . +.Pp +basename.c +.Pp +http://daringfireball.net/projects/markdown/syntax +.Sh BUGS +Error handling is minimal at best. diff --git a/r2/r2/lib/contrib/discount-1.6.0/mkd-extensions.7 b/r2/r2/lib/contrib/discount/mkd-extensions.7 similarity index 99% rename from r2/r2/lib/contrib/discount-1.6.0/mkd-extensions.7 rename to r2/r2/lib/contrib/discount/mkd-extensions.7 index 91d9156cfb..7e96d3a40d 100644 --- a/r2/r2/lib/contrib/discount-1.6.0/mkd-extensions.7 +++ b/r2/r2/lib/contrib/discount/mkd-extensions.7 @@ -169,6 +169,7 @@ David Parsons .Sh SEE ALSO .Xr markdown 1 , .Xr markdown 3 , +.Xr mkd-callbacks 3 , .Xr mkd-functions 3 , .Xr mkd-line 3 , .Xr mkd-extensions 7 . diff --git a/r2/r2/lib/contrib/discount-1.6.0/mkd-functions.3 b/r2/r2/lib/contrib/discount/mkd-functions.3 similarity index 100% rename from r2/r2/lib/contrib/discount-1.6.0/mkd-functions.3 rename to r2/r2/lib/contrib/discount/mkd-functions.3 diff --git a/r2/r2/lib/contrib/discount-1.6.0/mkd-line.3 b/r2/r2/lib/contrib/discount/mkd-line.3 similarity index 100% rename from r2/r2/lib/contrib/discount-1.6.0/mkd-line.3 rename to r2/r2/lib/contrib/discount/mkd-line.3 diff --git a/r2/r2/lib/contrib/discount-1.6.0/mkd2html.c b/r2/r2/lib/contrib/discount/mkd2html.c similarity index 100% rename from r2/r2/lib/contrib/discount-1.6.0/mkd2html.c rename to r2/r2/lib/contrib/discount/mkd2html.c diff --git a/r2/r2/lib/contrib/discount-1.6.0/mkdio.c b/r2/r2/lib/contrib/discount/mkdio.c similarity index 92% rename from r2/r2/lib/contrib/discount-1.6.0/mkdio.c rename to r2/r2/lib/contrib/discount/mkdio.c index 86542b73ac..0e930450ed 100644 --- a/r2/r2/lib/contrib/discount-1.6.0/mkdio.c +++ b/r2/r2/lib/contrib/discount/mkdio.c @@ -217,14 +217,6 @@ markdown(Document *document, FILE *out, int flags) } -void -mkd_basename(Document *document, char *base) -{ - if ( document ) - document->base = base; -} - - /* write out a Cstring, mangled into a form suitable for `ctx ) f->ctx->e_url = edit; + if ( f ) + f->cb.e_url = edit; } /* set the url options callback */ void -mkd_e_flags(Document *f, e_func edit) +mkd_e_flags(Document *f, mkd_callback_t edit) { - if ( f && f->ctx ) f->ctx->e_flags = edit; + if ( f ) + f->cb.e_flags = edit; } /* set the url display/options deallocator */ void -mkd_e_free(Document *f, void (*dealloc)(void*,void*)) +mkd_e_free(Document *f, mkd_free_t dealloc) { - if ( f && f->ctx ) f->ctx->e_free = dealloc; + if ( f ) + f->cb.e_free = dealloc; } -/* set the url display/options context field +/* set the url display/options context data field */ void -mkd_e_context(Document *f, void *context) +mkd_e_data(Document *f, void *data) { - if ( f && f->ctx ) f->ctx->e_context = context; + if ( f ) + f->cb.e_data = data; } diff --git a/r2/r2/lib/contrib/discount-1.6.0/mkdio.h b/r2/r2/lib/contrib/discount/mkdio.h similarity index 90% rename from r2/r2/lib/contrib/discount-1.6.0/mkdio.h rename to r2/r2/lib/contrib/discount/mkdio.h index fc9ac3e7a1..3e30c6fb7e 100644 --- a/r2/r2/lib/contrib/discount-1.6.0/mkdio.h +++ b/r2/r2/lib/contrib/discount/mkdio.h @@ -50,11 +50,13 @@ int mkd_generateline(char *, int, FILE*, int); /* url generator callbacks */ -typedef char * (e_func)(char*, int, void*); -void mkd_e_url(void *, e_func); -void mkd_e_flags(void *, e_func); -void mkd_e_free(void *, void (*dealloc)(void*, void*) ); -void mkd_e_context(void *, void *); +typedef char * (*mkd_callback_t)(const char*, const int, void*); +typedef void (*mkd_free_t)(char*, void*); + +void mkd_e_url(void *, mkd_callback_t); +void mkd_e_flags(void *, mkd_callback_t); +void mkd_e_free(void *, mkd_free_t ); +void mkd_e_data(void *, void *); /* version#. */ diff --git a/r2/r2/lib/contrib/discount-1.6.0/resource.c b/r2/r2/lib/contrib/discount/resource.c similarity index 100% rename from r2/r2/lib/contrib/discount-1.6.0/resource.c rename to r2/r2/lib/contrib/discount/resource.c diff --git a/r2/r2/lib/contrib/discount-1.6.0/tests/autolink.t b/r2/r2/lib/contrib/discount/tests/autolink.t similarity index 67% rename from r2/r2/lib/contrib/discount-1.6.0/tests/autolink.t rename to r2/r2/lib/contrib/discount/tests/autolink.t index a471fea856..b19dcb3b15 100644 --- a/r2/r2/lib/contrib/discount-1.6.0/tests/autolink.t +++ b/r2/r2/lib/contrib/discount/tests/autolink.t @@ -1,27 +1,7 @@ -./echo 'Reddit-style automatic links' -rc=0 - -try() { - unset FLAGS - case "$1" in - -*) FLAGS=$1 - shift ;; - esac - - ./echo -n " $1" '..................................' | ./cols 36 - - Q=`./echo "$2" | ./markdown $FLAGS` +. tests/functions.sh - - if [ "$3" = "$Q" ]; then - ./echo " ok" - else - ./echo " FAILED" - ./echo "wanted: $3" - ./echo "got : $Q" - rc=1 - fi -} +title 'Reddit-style automatic links' +rc=0 try -fautolink 'single link' \ 'http://www.pell.portland.or.us/~orc/Code/discount' \ @@ -43,4 +23,5 @@ try -fautolink 'parenthesised (url)' \ try -fautolink 'token with trailing @' 'orc@' '

orc@

' +summary $0 exit $rc diff --git a/r2/r2/lib/contrib/discount-1.6.0/tests/automatic.t b/r2/r2/lib/contrib/discount/tests/automatic.t similarity index 60% rename from r2/r2/lib/contrib/discount-1.6.0/tests/automatic.t rename to r2/r2/lib/contrib/discount/tests/automatic.t index 89c3e6ad97..2d91032312 100644 --- a/r2/r2/lib/contrib/discount-1.6.0/tests/automatic.t +++ b/r2/r2/lib/contrib/discount/tests/automatic.t @@ -1,41 +1,10 @@ -./echo "automatic links" +. tests/functions.sh + +title "automatic links" rc=0 MARKDOWN_FLAGS= -try() { - unset FLAGS - case "$1" in - -*) FLAGS=$1 - shift ;; - esac - - ./echo -n " $1" '..................................' | ./cols 36 - - Q=`./echo "$2" | ./markdown $FLAGS` - - - if [ "$3" = "$Q" ]; then - ./echo " ok" - else - ./echo " FAILED" - ./echo "wanted: $3" - ./echo "got : $Q" - rc=1 - fi -} - -match() { - ./echo -n " $1" '..................................' | ./cols 36 - - if ./echo "$2" | ./markdown | grep "$3" >/dev/null; then - ./echo " ok" - else - ./echo " FAILED" - rc=1 - fi -} - try 'http url' '' '

http://here

' try 'ftp url' '' '

ftp://here

' match '' '' '' '' '' '' '' '' 'foo

' + +try -fautolink 'autolink url with trailing \' \ + 'http://a.com/\' \ + '

http://a.com/\

' + +summary $0 +exit $rc diff --git a/r2/r2/lib/contrib/discount/tests/callbacks.t b/r2/r2/lib/contrib/discount/tests/callbacks.t new file mode 100644 index 0000000000..28217bbecc --- /dev/null +++ b/r2/r2/lib/contrib/discount/tests/callbacks.t @@ -0,0 +1,17 @@ +. tests/functions.sh + +title "callbacks" + +rc=0 +MARKDOWN_FLAGS= + +try -bZZZ 'url modification' \ +'[a](/b)' \ +'

a

' + +try -EZZZ 'additional flags' \ +'[a](/b)' \ +'

a

' + +summary $0 +exit $rc diff --git a/r2/r2/lib/contrib/discount-1.6.0/tests/chrome.text b/r2/r2/lib/contrib/discount/tests/chrome.text similarity index 100% rename from r2/r2/lib/contrib/discount-1.6.0/tests/chrome.text rename to r2/r2/lib/contrib/discount/tests/chrome.text diff --git a/r2/r2/lib/contrib/discount/tests/code.t b/r2/r2/lib/contrib/discount/tests/code.t new file mode 100644 index 0000000000..3227ecf32a --- /dev/null +++ b/r2/r2/lib/contrib/discount/tests/code.t @@ -0,0 +1,31 @@ +. tests/functions.sh + +title "code blocks" + +rc=0 +MARKDOWN_FLAGS= + +try 'format for code block html' \ +' this is + code' \ + '
this is
+code
+
' + +try 'unclosed single backtick' '`hi there' '

`hi there

' +try 'unclosed double backtick' '``hi there' '

``hi there

' +try 'remove space around code' '`` hi there ``' '

hi there

' +try 'code containing backticks' '`` a```b ``' '

a```b

' +try 'backslash before backtick' '`a\`' '

a\

' +try '`>`' '`>`' '

>

' +try '`` ` ``' '`` ` ``' '

`

' +try '````` ``` `' '````` ``` `' '

`` `

' +try '````` ` ```' '````` ` ```' '

`` `

' +try 'backslashes in code(1)' ' printf "%s: \n", $1;' \ +'
printf "%s: \n", $1;
+
' +try 'backslashes in code(2)' '`printf "%s: \n", $1;`' \ +'

printf "%s: \n", $1;

' + +summary $0 +exit $rc diff --git a/r2/r2/lib/contrib/discount-1.6.0/tests/compat.t b/r2/r2/lib/contrib/discount/tests/compat.t similarity index 57% rename from r2/r2/lib/contrib/discount-1.6.0/tests/compat.t rename to r2/r2/lib/contrib/discount/tests/compat.t index 2ce7a14f78..f3256c15f8 100644 --- a/r2/r2/lib/contrib/discount-1.6.0/tests/compat.t +++ b/r2/r2/lib/contrib/discount/tests/compat.t @@ -1,29 +1,10 @@ -./echo "markdown 1.0 compatability" +. tests/functions.sh + +title "markdown 1.0 compatability" rc=0 MARKDOWN_FLAGS= -try() { - unset FLAGS - case "$1" in - -*) FLAGS=$1 - shift ;; - esac - - ./echo -n " $1" '..................................' | ./cols 36 - - Q=`./echo "$2" | ./markdown $FLAGS` - - if [ "$3" = "$Q" ]; then - ./echo " ok" - else - ./echo " FAILED" - ./echo "wanted: $3" - ./echo "got : $Q" - rc=1 - fi -} - LINKY='[this] is a test [this]: /this' @@ -44,4 +25,5 @@ try -f1.0 'trailing whitespace (-f1.0)' "$WHITESPACE" '
white space''
 and more
 
' +summary $0 exit $rc diff --git a/r2/r2/lib/contrib/discount/tests/crash.t b/r2/r2/lib/contrib/discount/tests/crash.t new file mode 100644 index 0000000000..b553ce5c76 --- /dev/null +++ b/r2/r2/lib/contrib/discount/tests/crash.t @@ -0,0 +1,30 @@ +. tests/functions.sh + +title "crashes" + +rc=0 +MARKDOWN_FLAGS= + +try 'zero-length input' '' '' + +try 'hanging quote in list' \ +' * > this should not die + +no.' \ +'
    +
  • this should not die

  • +
+ + +

no.

' + +try 'dangling list item' ' - ' \ +'
    +
  • +
' + +try -bHOHO 'empty []() with baseurl' '[]()' '

' +try 'unclosed html block' '
/dev/null || exit 0 -./echo "%div% blocks" +. tests/functions.sh + +title "%div% blocks" rc=0 MARKDOWN_FLAGS= -try() { - unset FLAGS - case "$1" in - -*) FLAGS=$1 - shift ;; - esac - - ./echo -n " $1" '..................................' | ./cols 36 - - Q=`./echo "$2" | ./markdown $FLAGS` - - - if [ "$3" = "$Q" ]; then - ./echo " ok" - else - ./echo " FAILED" - ./echo "wanted: $3" - ./echo "got : $Q" - rc=1 - fi -} - try 'simple >%div% block' \ '>%this% this this' \ @@ -63,5 +43,5 @@ more' \

more

' - +summary $0 exit $rc diff --git a/r2/r2/lib/contrib/discount-1.6.0/tests/dl.t b/r2/r2/lib/contrib/discount/tests/dl.t similarity index 61% rename from r2/r2/lib/contrib/discount-1.6.0/tests/dl.t rename to r2/r2/lib/contrib/discount/tests/dl.t index 4c3a53a6e2..b912f67272 100644 --- a/r2/r2/lib/contrib/discount-1.6.0/tests/dl.t +++ b/r2/r2/lib/contrib/discount/tests/dl.t @@ -1,29 +1,10 @@ -./echo "definition lists" +. tests/functions.sh + +title "definition lists" rc=0 MARKDOWN_FLAGS= -try() { - unset FLAGS - case "$1" in - -*) FLAGS=$1 - shift ;; - esac - - ./echo -n " $1" '..................................' | ./cols 36 - - Q=`./echo "$2" | ./markdown $FLAGS` - - if [ "$3" = "$Q" ]; then - ./echo " ok" - else - ./echo " FAILED" - ./echo "wanted: $3" - ./echo "got : $Q" - rc=1 - fi -} - SRC=' =this= is an ugly @@ -66,4 +47,5 @@ else fi +summary $0 exit $rc diff --git a/r2/r2/lib/contrib/discount-1.6.0/tests/embedlinks.text b/r2/r2/lib/contrib/discount/tests/embedlinks.text similarity index 100% rename from r2/r2/lib/contrib/discount-1.6.0/tests/embedlinks.text rename to r2/r2/lib/contrib/discount/tests/embedlinks.text diff --git a/r2/r2/lib/contrib/discount-1.6.0/tests/emphasis.t b/r2/r2/lib/contrib/discount/tests/emphasis.t similarity index 63% rename from r2/r2/lib/contrib/discount-1.6.0/tests/emphasis.t rename to r2/r2/lib/contrib/discount/tests/emphasis.t index 60e631fb88..94f7b041b2 100644 --- a/r2/r2/lib/contrib/discount-1.6.0/tests/emphasis.t +++ b/r2/r2/lib/contrib/discount/tests/emphasis.t @@ -1,30 +1,10 @@ -./echo "emphasis" +. tests/functions.sh + +title "emphasis" rc=0 MARKDOWN_FLAGS= -try() { - unset FLAGS - case "$1" in - -*) FLAGS=$1 - shift ;; - esac - - ./echo -n " $1" '..................................' | ./cols 36 - - Q=`./echo "$2" | ./markdown $FLAGS` - - if [ "$3" = "$Q" ]; then - ./echo " ok" - else - ./echo " FAILED" - ./echo "wanted: $3" - ./echo "got : $Q" - rc=1 - fi -} - - try '*hi* -> hi' '*hi*' '

hi

' try '* -> *' 'A * A' '

A * A

' try -fstrict '***A**B*' '***A**B*' '

AB

' @@ -37,4 +17,5 @@ if ./markdown -V | grep RELAXED >/dev/null; then try -fstrict '_A_B with -fstrict' '_A_B' '

AB

' fi +summary $0 exit $rc diff --git a/r2/r2/lib/contrib/discount/tests/flow.t b/r2/r2/lib/contrib/discount/tests/flow.t new file mode 100644 index 0000000000..44cf53a705 --- /dev/null +++ b/r2/r2/lib/contrib/discount/tests/flow.t @@ -0,0 +1,33 @@ +. tests/functions.sh + +title "paragraph flow" + +rc=0 +MARKDOWN_FLAGS= + +try 'header followed by paragraph' \ + '###Hello, sailor### +And how are you today?' \ + '

Hello, sailor

+ +

And how are you today?

' + +try 'two lists punctuated with a HR' \ + '* A +* * * +* B +* C' \ + ' + + +
+ +' + +summary $0 +exit $rc diff --git a/r2/r2/lib/contrib/discount/tests/footnotes.t b/r2/r2/lib/contrib/discount/tests/footnotes.t new file mode 100644 index 0000000000..2c923b095e --- /dev/null +++ b/r2/r2/lib/contrib/discount/tests/footnotes.t @@ -0,0 +1,16 @@ +. tests/functions.sh + +title "footnotes" + +rc=0 +MARKDOWN_FLAGS= + +try 'a line with multiple []s' '[a][] [b][]:' '

[a][] [b][]:

' +try 'a valid footnote' \ + '[alink][] + +[alink]: link_me' \ + '

alink

' + +summary $0 +exit $rc diff --git a/r2/r2/lib/contrib/discount/tests/functions.sh b/r2/r2/lib/contrib/discount/tests/functions.sh new file mode 100644 index 0000000000..745cc80800 --- /dev/null +++ b/r2/r2/lib/contrib/discount/tests/functions.sh @@ -0,0 +1,77 @@ +__tests=0 +__passed=0 +__failed=0 +__title= + +title() { + __title="$*" + if [ "$VERBOSE" ]; then + ./echo "$__title" + else + ./echo -n "$__title" \ +'.................................................................' | ./cols 54 + fi +} + + +summary() { + if [ -z "$VERBOSE" ]; then + if [ $__failed -eq 0 ]; then + ./echo " OK" + else + ./echo + ./echo "$1: $__tests tests; $__failed failed/$__passed passed" + ./echo + fi + fi +} + + +try() { + unset FLAGS + case "$1" in + -*) FLAGS=$1 + shift ;; + esac + + testcase=`./echo -n " $1" '..................................' | ./cols 36` + __tests=`expr $__tests + 1` + + + test "$VERBOSE" && ./echo -n "$testcase" + + case "$2" in + -t*) Q=`./markdown $FLAGS "$2"` ;; + *) Q=`./echo "$2" | ./markdown $FLAGS` ;; + esac + + if [ "$3" = "$Q" ]; then + __passed=`expr $__passed + 1` + test $VERBOSE && ./echo " ok" + else + __failed=`expr $__failed + 1` + if [ -z "$VERBOSE" ]; then + ./echo + ./echo "$1" + fi + ./echo "wanted: $3" + ./echo "got : $Q" + rc=1 + fi +} + +match() { + testcase=`./echo -n " $1" '..................................' | ./cols 36` + + test $VERBOSE && ./echo -n "$testcase" + + if ./echo "$2" | ./markdown | grep "$3" >/dev/null; then + test $VERBOSE && ./echo " ok" + else + if [ -z "$VERBOSE" ]; then + ./echo + ./echo "$testcase" + fi + rc=1 + fi +} diff --git a/r2/r2/lib/contrib/discount-1.6.0/tests/header.t b/r2/r2/lib/contrib/discount/tests/header.t similarity index 64% rename from r2/r2/lib/contrib/discount-1.6.0/tests/header.t rename to r2/r2/lib/contrib/discount/tests/header.t index aaab824d66..d72a516a34 100644 --- a/r2/r2/lib/contrib/discount-1.6.0/tests/header.t +++ b/r2/r2/lib/contrib/discount/tests/header.t @@ -1,31 +1,10 @@ -./echo "headers" +. tests/functions.sh + +title "headers" rc=0 MARKDOWN_FLAGS= -try() { - unset FLAGS - case "$1" in - -*) FLAGS=$1 - shift ;; - esac - - S=`./echo -n "$1" '..................................' | ./cols 34` - ./echo -n " $S " - - Q=`./echo "$2" | ./markdown $FLAGS` - - - if [ "$3" = "$Q" ]; then - ./echo "ok" - else - ./echo "FAILED" - ./echo "wanted: $3" - ./echo "got : $Q" - rc=1 - fi -} - try 'single #' '#' '

#

' try 'empty ETX' '##' '

#

' try 'single-char ETX (##W)' '##W' '

W

' @@ -43,4 +22,5 @@ try 'SETEXT with trailing whitespace' \ 'hello ===== ' '

hello

' +summary $0 exit $rc diff --git a/r2/r2/lib/contrib/discount-1.6.0/tests/html.t b/r2/r2/lib/contrib/discount/tests/html.t similarity index 75% rename from r2/r2/lib/contrib/discount-1.6.0/tests/html.t rename to r2/r2/lib/contrib/discount/tests/html.t index 9f75895c81..f233451747 100644 --- a/r2/r2/lib/contrib/discount-1.6.0/tests/html.t +++ b/r2/r2/lib/contrib/discount/tests/html.t @@ -1,29 +1,10 @@ -./echo "html blocks" +. tests/functions.sh + +title "html blocks" rc=0 MARKDOWN_FLAGS= -try() { - unset FLAGS - case "$1" in - -*) FLAGS=$1 - shift ;; - esac - - ./echo -n " $1" '..................................' | ./cols 36 - - Q=`./echo "$2" | ./markdown $FLAGS` - - if [ "$3" = "$Q" ]; then - ./echo " ok" - else - ./echo " FAILED" - ./echo "wanted: $3" - ./echo "got : $Q" - rc=1 - fi -} - try 'self-closing block tags (hr)' \ '
@@ -109,4 +90,48 @@ so is this' try 'unfinished tags' '<foo bar

' + +try 'comment with trailing text' 'a test' \ +' + + +

a test

' + +try 'block with trailing text' '

this is

a test' \ +'

this is

+ + +

a test

' + + +COMMENTS='line 1 + +line 2' + +try 'two comments' "$COMMENTS" \ +' + + +

line 1

+ + + + +

line 2

' + +COMMENTS='line 1 +line 2' + +try 'two adjacent comments' "$COMMENTS" \ +' + + +

line 1

+ + + + +

line 2

' + +summary $0 exit $rc diff --git a/r2/r2/lib/contrib/discount-1.6.0/tests/links.text b/r2/r2/lib/contrib/discount/tests/links.text similarity index 100% rename from r2/r2/lib/contrib/discount-1.6.0/tests/links.text rename to r2/r2/lib/contrib/discount/tests/links.text diff --git a/r2/r2/lib/contrib/discount-1.6.0/tests/linkylinky.t b/r2/r2/lib/contrib/discount/tests/linkylinky.t similarity index 87% rename from r2/r2/lib/contrib/discount-1.6.0/tests/linkylinky.t rename to r2/r2/lib/contrib/discount/tests/linkylinky.t index 5761f2ad16..3a81db36a8 100644 --- a/r2/r2/lib/contrib/discount-1.6.0/tests/linkylinky.t +++ b/r2/r2/lib/contrib/discount/tests/linkylinky.t @@ -1,30 +1,10 @@ -./echo "embedded links" +. tests/functions.sh + +title "embedded links" rc=0 MARKDOWN_FLAGS= -try() { - unset FLAGS - case "$1" in - -*) FLAGS=$1 - shift ;; - esac - - ./echo -n " $1" '..................................' | ./cols 36 - - Q=`./echo "$2" | ./markdown $FLAGS` - - - if [ "$3" = "$Q" ]; then - ./echo " ok" - else - ./echo " FAILED" - ./echo "wanted: $3" - ./echo "got : $Q" - rc=1 - fi -} - try 'url contains &' '[hehehe](u&rl)' '

hehehe

' try 'url contains +' '[hehehe](u+rl)' '

hehehe

' try 'url contains "' '[hehehe](u"rl)' '

hehehe

' @@ -121,4 +101,5 @@ try '[text] (text) not a link' \ '[test] (me)' \ '

[test] (me)

' +summary $0 exit $rc diff --git a/r2/r2/lib/contrib/discount/tests/linkypix.t b/r2/r2/lib/contrib/discount/tests/linkypix.t new file mode 100644 index 0000000000..5c7572ad3e --- /dev/null +++ b/r2/r2/lib/contrib/discount/tests/linkypix.t @@ -0,0 +1,21 @@ +. tests/functions.sh + +title "embedded images" + +rc=0 +MARKDOWN_FLAGS= + +try 'image with size extension' \ + '![picture](pic =200x200)' \ + '

picture

' + +try 'image with height' \ + '![picture](pic =x200)' \ + '

picture

' + +try 'image with width' \ + '![picture](pic =200x)' \ + '

picture

' + +summary $0 +exit $rc diff --git a/r2/r2/lib/contrib/discount-1.6.0/tests/list.t b/r2/r2/lib/contrib/discount/tests/list.t similarity index 84% rename from r2/r2/lib/contrib/discount-1.6.0/tests/list.t rename to r2/r2/lib/contrib/discount/tests/list.t index 8ffacda2af..a7493dac9a 100644 --- a/r2/r2/lib/contrib/discount-1.6.0/tests/list.t +++ b/r2/r2/lib/contrib/discount/tests/list.t @@ -1,29 +1,9 @@ -./echo "lists" +. tests/functions.sh +title "lists" rc=0 MARKDOWN_FLAGS= -try() { - unset FLAGS - case "$1" in - -*) FLAGS=$1 - shift ;; - esac - - ./echo -n " $1" '..................................' | ./cols 36 - - Q=`./echo "$2" | ./markdown $FLAGS` - - if [ "$3" = "$Q" ]; then - ./echo " ok" - else - ./echo " FAILED" - ./echo "wanted: $3" - ./echo "got : $Q" - rc=1 - fi -} - try 'two separated items' \ ' * A @@ -175,4 +155,5 @@ if ./markdown -V | grep DL_TAG >/dev/null; then fi +summary $0 exit $rc diff --git a/r2/r2/lib/contrib/discount-1.6.0/tests/list3deep.t b/r2/r2/lib/contrib/discount/tests/list3deep.t similarity index 65% rename from r2/r2/lib/contrib/discount-1.6.0/tests/list3deep.t rename to r2/r2/lib/contrib/discount/tests/list3deep.t index f28d57fa1a..5909055d83 100644 --- a/r2/r2/lib/contrib/discount-1.6.0/tests/list3deep.t +++ b/r2/r2/lib/contrib/discount/tests/list3deep.t @@ -1,29 +1,9 @@ -./echo "deeply nested lists" +. tests/functions.sh +title "deeply nested lists" rc=0 MARKDOWN_FLAGS= -try() { - unset FLAGS - case "$1" in - -*) FLAGS=$1 - shift ;; - esac - - ./echo -n " $1" '..................................' | ./cols 36 - - Q=`./echo "$2" | ./markdown $FLAGS` - - if [ "$3" = "$Q" ]; then - ./echo " ok" - else - ./echo " FAILED" - ./echo "wanted: $3" - ./echo "got : $Q" - rc=1 - fi -} - LIST=' * top-level list ( list 1) + second-level list (list 2) @@ -54,4 +34,5 @@ RSLT='
    try 'thrice-nested lists' "$LIST" "$RSLT" +summary $0 exit $rc diff --git a/r2/r2/lib/contrib/discount/tests/misc.t b/r2/r2/lib/contrib/discount/tests/misc.t new file mode 100644 index 0000000000..969ca3b219 --- /dev/null +++ b/r2/r2/lib/contrib/discount/tests/misc.t @@ -0,0 +1,12 @@ +. tests/functions.sh + +title "misc" + +rc=0 +MARKDOWN_FLAGS= + +try 'single paragraph' 'AAA' '

    AAA

    ' +try '< -> <' '<' '

    <

    ' + +summary $0 +exit $rc diff --git a/r2/r2/lib/contrib/discount-1.6.0/tests/pandoc.t b/r2/r2/lib/contrib/discount/tests/pandoc.t similarity index 64% rename from r2/r2/lib/contrib/discount-1.6.0/tests/pandoc.t rename to r2/r2/lib/contrib/discount/tests/pandoc.t index 9c1e7fb57d..4cfaf3ddea 100644 --- a/r2/r2/lib/contrib/discount-1.6.0/tests/pandoc.t +++ b/r2/r2/lib/contrib/discount/tests/pandoc.t @@ -1,31 +1,10 @@ -./echo "pandoc headers" +. tests/functions.sh + +title "pandoc headers" rc=0 MARKDOWN_FLAGS= -try() { - unset FLAGS - case "$1" in - -*) FLAGS=$1 - shift ;; - esac - - ./echo -n " $1" '..................................' | ./cols 36 - - Q=`./echo "$2" | ./markdown $FLAGS` - - - if [ "$3" = "$Q" ]; then - ./echo " ok" - else - ./echo " FAILED" - ./echo "wanted: $3" - ./echo "got : $Q" - rc=1 - fi -} - - HEADER='% title % author(s) % date' @@ -71,4 +50,5 @@ else fi +summary $0 exit $rc diff --git a/r2/r2/lib/contrib/discount/tests/para.t b/r2/r2/lib/contrib/discount/tests/para.t new file mode 100644 index 0000000000..29445e56b6 --- /dev/null +++ b/r2/r2/lib/contrib/discount/tests/para.t @@ -0,0 +1,19 @@ +. tests/functions.sh + +title "paragraph blocking" + +rc=0 +MARKDOWN_FLAGS= + +try 'paragraph followed by code' \ + 'a + b' \ + '

    a

    + +
    b
    +
    ' + +try 'single-line paragraph' 'a' '

    a

    ' + +summary $0 +exit $rc diff --git a/r2/r2/lib/contrib/discount/tests/paranoia.t b/r2/r2/lib/contrib/discount/tests/paranoia.t new file mode 100644 index 0000000000..a12147b12a --- /dev/null +++ b/r2/r2/lib/contrib/discount/tests/paranoia.t @@ -0,0 +1,12 @@ +. tests/functions.sh + +title "paranoia" + +rc=0 +MARKDOWN_FLAGS= + +try -fsafelink 'bogus url (-fsafelink)' '[test](bad:protocol)' '

    [test](bad:protocol)

    ' +try -fnosafelink 'bogus url (-fnosafelink)' '[test](bad:protocol)' '

    test

    ' + +summary $0 +exit $rc diff --git a/r2/r2/lib/contrib/discount-1.6.0/tests/peculiarities.t b/r2/r2/lib/contrib/discount/tests/peculiarities.t similarity index 60% rename from r2/r2/lib/contrib/discount-1.6.0/tests/peculiarities.t rename to r2/r2/lib/contrib/discount/tests/peculiarities.t index 8a199bd3dd..3f3b63b584 100644 --- a/r2/r2/lib/contrib/discount-1.6.0/tests/peculiarities.t +++ b/r2/r2/lib/contrib/discount/tests/peculiarities.t @@ -1,29 +1,10 @@ -./echo "markup peculiarities" +. tests/functions.sh + +title "markup peculiarities" rc=0 MARKDOWN_FLAGS= -try() { - unset FLAGS - case "$1" in - -*) FLAGS=$1 - shift ;; - esac - - ./echo -n " $1" '..................................' | ./cols 36 - - Q=`./echo "$2" | ./markdown $FLAGS` - - if [ "$3" = "$Q" ]; then - ./echo " ok" - else - ./echo " FAILED" - ./echo "wanted: $3" - ./echo "got : $Q" - rc=1 - fi -} - try 'list followed by header .......... ' \ " - AAA @@ -63,4 +44,5 @@ try -fnohtml 'markdown
    with -fnohtml' 'foo is' '

    foo
    is

    ' +summary $0 exit $rc diff --git a/r2/r2/lib/contrib/discount-1.6.0/tests/pseudo.t b/r2/r2/lib/contrib/discount/tests/pseudo.t similarity index 58% rename from r2/r2/lib/contrib/discount-1.6.0/tests/pseudo.t rename to r2/r2/lib/contrib/discount/tests/pseudo.t index e2d8b76359..921f308d63 100644 --- a/r2/r2/lib/contrib/discount-1.6.0/tests/pseudo.t +++ b/r2/r2/lib/contrib/discount/tests/pseudo.t @@ -1,35 +1,18 @@ -./echo "pseudo-protocols" +. tests/functions.sh + +title "pseudo-protocols" rc=0 MARKDOWN_FLAGS= -try() { - unset FLAGS - case "$1" in - -*) FLAGS=$1 - shift ;; - esac - - ./echo -n " $1" '..................................' | ./cols 36 - - Q=`./echo "$2" | ./markdown $FLAGS` - - - if [ "$3" = "$Q" ]; then - ./echo " ok" - else - ./echo " FAILED" - ./echo "wanted: $3" - ./echo "got : $Q" - rc=1 - fi -} - try '[](id:) links' '[foo](id:bar)' '

    foo

    ' try -fnoext '[](id:) links with -fnoext' '[foo](id:bar)' '

    [foo](id:bar)

    ' try '[](class:) links' '[foo](class:bar)' '

    foo

    ' try -fnoext '[](class:) links with -fnoext' '[foo](class:bar)' '

    [foo](class:bar)

    ' +try '[](lang:) links' '[foo](lang:en)' '

    foo

    ' +try -fnoext '[](lang:) links with -fnoext' '[foo](lang:en)' '

    [foo](lang:en)

    ' try '[](raw:) links' '[foo](raw:bar)' '

    bar

    ' try -fnoext '[](raw:) links with -fnoext' '[foo](raw:bar)' '

    [foo](raw:bar)

    ' +summary $0 exit $rc diff --git a/r2/r2/lib/contrib/discount/tests/reddit.t b/r2/r2/lib/contrib/discount/tests/reddit.t new file mode 100644 index 0000000000..268cbcfcba --- /dev/null +++ b/r2/r2/lib/contrib/discount/tests/reddit.t @@ -0,0 +1,27 @@ +. tests/functions.sh + +title "bugs & misfeatures found during the Reddit rollout" + +rc=0 +MARKDOWN_FLAGS= + +try 'smiley faces?' '[8-9] <]:-( x ---> [4]' \ + '

    [8-9] <]:–( x —–> [4]

    ' + +try 'really long ETX headers' \ + '#####################################################hi' \ + '
    ###############################################hi
    ' + +try 'unescaping " " inside `code`' \ +'`foo +bar`' \ +'

    foo +bar

    ' + +try 'unescaping " " inside []()' \ +'[foo](bar +bar)' \ +'

    foo

    ' + +summary $0 +exit $rc diff --git a/r2/r2/lib/contrib/discount/tests/reparse.t b/r2/r2/lib/contrib/discount/tests/reparse.t new file mode 100644 index 0000000000..93e11b521a --- /dev/null +++ b/r2/r2/lib/contrib/discount/tests/reparse.t @@ -0,0 +1,14 @@ +. tests/functions.sh + +title "footnotes inside reparse sections" + +rc=0 + +try 'footnote inside [] section' \ + '[![foo][]](bar) + +[foo]: bar2' \ + '

    foo

    ' + +summary $0 +exit $rc diff --git a/r2/r2/lib/contrib/discount-1.6.0/tests/schiraldi.t b/r2/r2/lib/contrib/discount/tests/schiraldi.t similarity index 88% rename from r2/r2/lib/contrib/discount-1.6.0/tests/schiraldi.t rename to r2/r2/lib/contrib/discount/tests/schiraldi.t index 2d90813dae..a576fdd698 100644 --- a/r2/r2/lib/contrib/discount-1.6.0/tests/schiraldi.t +++ b/r2/r2/lib/contrib/discount/tests/schiraldi.t @@ -1,31 +1,10 @@ -./echo "Bugs & misfeatures reported by Mike Schiraldi" +. tests/functions.sh + +title "Bugs & misfeatures reported by Mike Schiraldi" rc=0 MARKDOWN_FLAGS= -try() { - unset FLAGS - case "$1" in - -*) FLAGS=$1 - shift ;; - esac - - S=`./echo -n "$1" '..................................' | ./cols 34` - ./echo -n " $S " - - Q=`./echo "$2" | ./markdown $FLAGS` - - - if [ "$3" = "$Q" ]; then - ./echo "ok" - else - ./echo "FAILED" - ./echo "wanted: $3" - ./echo "got : $Q" - rc=1 - fi -} - try -fnohtml 'breaks with -fnohtml' 'foo bar' '

    foo
    bar

    ' @@ -100,5 +79,13 @@ try -fautolink 'security hole with \" in []()' \ '[XSS](/ "\"=\"\"onmouseover='$Q'alert(String.fromCharCode(88,83,83))'$Q'")' \ '

    XSS

    ' +try -fautolink 'autolink and prefix fragment' \ +'xxxxxxx http://x.com/ + +xxx xxxxht' \ +'

    xxxxxxx http://x.com/

    + +

    xxx xxxxht

    ' +summary $0 exit $rc diff --git a/r2/r2/lib/contrib/discount-1.6.0/tests/smarty.t b/r2/r2/lib/contrib/discount/tests/smarty.t similarity index 73% rename from r2/r2/lib/contrib/discount-1.6.0/tests/smarty.t rename to r2/r2/lib/contrib/discount/tests/smarty.t index e3e6e34575..eefa475ee1 100644 --- a/r2/r2/lib/contrib/discount-1.6.0/tests/smarty.t +++ b/r2/r2/lib/contrib/discount/tests/smarty.t @@ -1,31 +1,10 @@ -./echo "smarty pants" +. tests/functions.sh + +title "smarty pants" rc=0 MARKDOWN_FLAGS=0x0; export MARKDOWN_FLAGS -try() { - unset FLAGS - case "$1" in - -*) FLAGS="$1" - shift ;; - esac - - ./echo -n " $1" '..................................' | ./cols 36 - - Q=`./echo "$2" | ./markdown $FLAGS` - - - if [ "$3" = "$Q" ]; then - ./echo " ok" - else - ./echo " FAILED" - ./echo "wanted: $3" - ./echo "got : $Q" - rc=1 - fi -} - - try '(c) -> ©' '(c)' '

    ©

    ' try '(r) -> ®' '(r)' '

    ®

    ' try '(tm) -> ™' '(tm)' '

    ' @@ -47,4 +26,5 @@ if ./markdown -V | grep SUPERSCRIPT >/dev/null; then try -frelax 'A^B in link title' '[link](here "A^B")' '

    link

    ' fi +summary $0 exit $rc diff --git a/r2/r2/lib/contrib/discount-1.6.0/tests/snakepit.t b/r2/r2/lib/contrib/discount/tests/snakepit.t similarity index 62% rename from r2/r2/lib/contrib/discount-1.6.0/tests/snakepit.t rename to r2/r2/lib/contrib/discount/tests/snakepit.t index 886806fea8..447da605aa 100644 --- a/r2/r2/lib/contrib/discount-1.6.0/tests/snakepit.t +++ b/r2/r2/lib/contrib/discount/tests/snakepit.t @@ -1,30 +1,10 @@ -./echo "The snakepit of Markdown.pl compatability" +. tests/functions.sh + +title "The snakepit of Markdown.pl compatability" rc=0 MARKDOWN_FLAGS= -try() { - unset FLAGS - case "$1" in - -*) FLAGS=$1 - shift ;; - esac - - ./echo -n " $1" '..................................' | ./cols 36 - - Q=`./echo "$2" | ./markdown $FLAGS` - - - if [ "$3" = "$Q" ]; then - ./echo " ok" - else - ./echo " FAILED" - ./echo "wanted: $3" - ./echo "got : $Q" - rc=1 - fi -} - try '[](single quote) text (quote)' \ "[foo](http://Poe's law) will make this fail ('no, it won't!') here."\ '

    foo here.

    ' @@ -42,4 +22,5 @@ try ' (2)' \ try 'paragraph
    oddity' 'EOF ' '

    EOF

    ' +summary $0 exit $rc diff --git a/r2/r2/lib/contrib/discount/tests/style.t b/r2/r2/lib/contrib/discount/tests/style.t new file mode 100644 index 0000000000..62303c96a6 --- /dev/null +++ b/r2/r2/lib/contrib/discount/tests/style.t @@ -0,0 +1,17 @@ +. tests/functions.sh + +title "styles" + +rc=0 +MARKDOWN_FLAGS= + +try '' '' + +ASK='' + +try '