Skip to content
This repository has been archived by the owner on Sep 24, 2022. It is now read-only.

Commit

Permalink
Updated Sundown files.
Browse files Browse the repository at this point in the history
  • Loading branch information
FSX committed Oct 21, 2012
1 parent 45e4cbf commit d2547c7
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "vendor/sundown"]
path = vendor/sundown
url = git://github.com/tanoku/sundown.git
url = git://github.com/vmg/sundown.git
6 changes: 3 additions & 3 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
News/Changelog
==============

### 1.0.3 (2012-07-??)
### 1.0.3 (2012-11-??)

- `scripts/misaka`: Read stdin when no file is specified. ([#22][])
- Updated Sundown files; See commits from Mar 29, 2012 to May 02, 2012:
https://github.com/tanoku/sundown/commits/master/
- Updated Sundown files; See commits from Mar 29, 2012 to Oct 19, 2012:
https://github.com/vmg/sundown/commits/master/

[#22]: https://github.com/FSX/misaka/pull/22

Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The Python binding for Sundown_, a markdown parsing library.

Documentation can be found at: http://misaka.61924.nl/

.. _Sundown: https://github.com/tanoku/sundown
.. _Sundown: https://github.com/vmg/sundown


Installation
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def run(self):


class VendorCommand(BaseCommand):
description = 'update Sundown files. Use `git submodule foreach git pull` to the most recent files'
description = 'update Sundown files. Use `git submodule init;git submodule update` to the most recent files'
def run(self):
files = []
dest = os.path.join(dirname, 'src/sundown')
Expand Down
64 changes: 48 additions & 16 deletions src/sundown/autolink.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

#include "buffer.h"
#include "autolink.h"

#include <string.h>
#include <stdlib.h>
Expand Down Expand Up @@ -48,7 +49,7 @@ sd_autolink_issafe(const uint8_t *link, size_t link_len)
}

static size_t
autolink_delim(uint8_t *data, size_t link_end, size_t offset, size_t size)
autolink_delim(uint8_t *data, size_t link_end, size_t max_rewind, size_t size)
{
uint8_t cclose, copen = 0;
size_t i;
Expand Down Expand Up @@ -132,7 +133,7 @@ autolink_delim(uint8_t *data, size_t link_end, size_t offset, size_t size)
}

static size_t
check_domain(uint8_t *data, size_t size)
check_domain(uint8_t *data, size_t size, int allow_short)
{
size_t i, np = 0;

Expand All @@ -144,31 +145,45 @@ check_domain(uint8_t *data, size_t size)
else if (!isalnum(data[i]) && data[i] != '-') break;
}

/* a valid domain needs to have at least a dot.
* that's as far as we get */
return np ? i : 0;
if (allow_short) {
/* We don't need a valid domain in the strict sense (with
* least one dot; so just make sure it's composed of valid
* domain characters and return the length of the the valid
* sequence. */
return i;
} else {
/* a valid domain needs to have at least a dot.
* that's as far as we get */
return np ? i : 0;
}
}

size_t
sd_autolink__www(size_t *rewind_p, struct buf *link, uint8_t *data, size_t offset, size_t size)
sd_autolink__www(
size_t *rewind_p,
struct buf *link,
uint8_t *data,
size_t max_rewind,
size_t size,
unsigned int flags)
{
size_t link_end;

if (offset > 0 && !ispunct(data[-1]) && !isspace(data[-1]))
if (max_rewind > 0 && !ispunct(data[-1]) && !isspace(data[-1]))
return 0;

if (size < 4 || memcmp(data, "www.", strlen("www.")) != 0)
return 0;

link_end = check_domain(data, size);
link_end = check_domain(data, size, 0);

if (link_end == 0)
return 0;

while (link_end < size && !isspace(data[link_end]))
link_end++;

link_end = autolink_delim(data, link_end, offset, size);
link_end = autolink_delim(data, link_end, max_rewind, size);

if (link_end == 0)
return 0;
Expand All @@ -180,12 +195,18 @@ sd_autolink__www(size_t *rewind_p, struct buf *link, uint8_t *data, size_t offse
}

size_t
sd_autolink__email(size_t *rewind_p, struct buf *link, uint8_t *data, size_t offset, size_t size)
sd_autolink__email(
size_t *rewind_p,
struct buf *link,
uint8_t *data,
size_t max_rewind,
size_t size,
unsigned int flags)
{
size_t link_end, rewind;
int nb = 0, np = 0;

for (rewind = 0; rewind < offset; ++rewind) {
for (rewind = 0; rewind < max_rewind; ++rewind) {
uint8_t c = data[-rewind - 1];

if (isalnum(c))
Expand Down Expand Up @@ -217,7 +238,7 @@ sd_autolink__email(size_t *rewind_p, struct buf *link, uint8_t *data, size_t off
if (link_end < 2 || nb != 1 || np == 0)
return 0;

link_end = autolink_delim(data, link_end, offset, size);
link_end = autolink_delim(data, link_end, max_rewind, size);

if (link_end == 0)
return 0;
Expand All @@ -229,29 +250,40 @@ sd_autolink__email(size_t *rewind_p, struct buf *link, uint8_t *data, size_t off
}

size_t
sd_autolink__url(size_t *rewind_p, struct buf *link, uint8_t *data, size_t offset, size_t size)
sd_autolink__url(
size_t *rewind_p,
struct buf *link,
uint8_t *data,
size_t max_rewind,
size_t size,
unsigned int flags)
{
size_t link_end, rewind = 0, domain_len;

if (size < 4 || data[1] != '/' || data[2] != '/')
return 0;

while (rewind < offset && isalpha(data[-rewind - 1]))
while (rewind < max_rewind && isalpha(data[-rewind - 1]))
rewind++;

if (!sd_autolink_issafe(data - rewind, size + rewind))
return 0;

link_end = strlen("://");

domain_len = check_domain(data + link_end, size - link_end);
domain_len = check_domain(
data + link_end,
size - link_end,
flags & SD_AUTOLINK_SHORT_DOMAINS);

if (domain_len == 0)
return 0;

link_end += domain_len;
while (link_end < size && !isspace(data[link_end]))
link_end++;

link_end = autolink_delim(data, link_end, offset, size);
link_end = autolink_delim(data, link_end, max_rewind, size);

if (link_end == 0)
return 0;
Expand Down
21 changes: 14 additions & 7 deletions src/sundown/autolink.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,24 @@
extern "C" {
#endif

extern int
enum {
SD_AUTOLINK_SHORT_DOMAINS = (1 << 0),
};

int
sd_autolink_issafe(const uint8_t *link, size_t link_len);

extern size_t
sd_autolink__www(size_t *rewind_p, struct buf *link, uint8_t *data, size_t offset, size_t size);
size_t
sd_autolink__www(size_t *rewind_p, struct buf *link,
uint8_t *data, size_t offset, size_t size, unsigned int flags);

extern size_t
sd_autolink__email(size_t *rewind_p, struct buf *link, uint8_t *data, size_t offset, size_t size);
size_t
sd_autolink__email(size_t *rewind_p, struct buf *link,
uint8_t *data, size_t offset, size_t size, unsigned int flags);

extern size_t
sd_autolink__url(size_t *rewind_p, struct buf *link, uint8_t *data, size_t offset, size_t size);
size_t
sd_autolink__url(size_t *rewind_p, struct buf *link,
uint8_t *data, size_t offset, size_t size, unsigned int flags);

#ifdef __cplusplus
}
Expand Down
13 changes: 9 additions & 4 deletions src/sundown/markdown.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ parse_emph1(struct buf *ob, struct sd_markdown *rndr, uint8_t *data, size_t size
if (data[i] == c && !_isspace(data[i - 1])) {

if (rndr->ext_flags & MKDEXT_NO_INTRA_EMPHASIS) {
if (!(i + 1 == size || _isspace(data[i + 1]) || ispunct(data[i + 1])))
if (i + 1 < size && isalnum(data[i + 1]))
continue;
}

Expand Down Expand Up @@ -596,6 +596,11 @@ char_emphasis(struct buf *ob, struct sd_markdown *rndr, uint8_t *data, size_t of
uint8_t c = data[0];
size_t ret;

if (rndr->ext_flags & MKDEXT_NO_INTRA_EMPHASIS) {
if (offset > 0 && !_isspace(data[-1]) && data[-1] != '>')
return 0;
}

if (size > 2 && data[1] != c) {
/* whitespace cannot follow an opening emphasis;
* strikethrough only takes two characters '~~' */
Expand Down Expand Up @@ -771,7 +776,7 @@ char_autolink_www(struct buf *ob, struct sd_markdown *rndr, uint8_t *data, size_

link = rndr_newbuf(rndr, BUFFER_SPAN);

if ((link_len = sd_autolink__www(&rewind, link, data, offset, size)) > 0) {
if ((link_len = sd_autolink__www(&rewind, link, data, offset, size, 0)) > 0) {
link_url = rndr_newbuf(rndr, BUFFER_SPAN);
BUFPUTSL(link_url, "http://");
bufput(link_url, link->data, link->size);
Expand Down Expand Up @@ -803,7 +808,7 @@ char_autolink_email(struct buf *ob, struct sd_markdown *rndr, uint8_t *data, siz

link = rndr_newbuf(rndr, BUFFER_SPAN);

if ((link_len = sd_autolink__email(&rewind, link, data, offset, size)) > 0) {
if ((link_len = sd_autolink__email(&rewind, link, data, offset, size, 0)) > 0) {
ob->size -= rewind;
rndr->cb.autolink(ob, link, MKDA_EMAIL, rndr->opaque);
}
Expand All @@ -823,7 +828,7 @@ char_autolink_url(struct buf *ob, struct sd_markdown *rndr, uint8_t *data, size_

link = rndr_newbuf(rndr, BUFFER_SPAN);

if ((link_len = sd_autolink__url(&rewind, link, data, offset, size)) > 0) {
if ((link_len = sd_autolink__url(&rewind, link, data, offset, size, 0)) > 0) {
ob->size -= rewind;
rndr->cb.autolink(ob, link, MKDA_NORMAL, rndr->opaque);
}
Expand Down
2 changes: 1 addition & 1 deletion vendor/sundown
Submodule sundown updated 4 files
+2 −2 README.markdown
+48 −16 src/autolink.c
+14 −7 src/autolink.h
+9 −4 src/markdown.c

0 comments on commit d2547c7

Please sign in to comment.