Skip to content

Commit

Permalink
Update for recent changes in cmark-gfm
Browse files Browse the repository at this point in the history
  • Loading branch information
KristopherGBaker committed Jun 3, 2019
1 parent 24629a5 commit 0cde9cc
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 28 deletions.
14 changes: 7 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: objective-c
osx_image: xcode10.1
osx_image: xcode10.2
env:
global:
- LC_CTYPE=en_US.UTF-8
Expand All @@ -9,21 +9,21 @@ env:
- MACOS_FRAMEWORK_SCHEME="libcmark_gfm-macOS"
- TVOS_FRAMEWORK_SCHEME="libcmark_gfm-tvOS"
- WATCHOS_FRAMEWORK_SCHEME="libcmark_gfm-watchOS"
- IOS_SDK=iphonesimulator12.1
- IOS_SDK=iphonesimulator12.2
- MACOS_SDK=macosx10.14
- TVOS_SDK=appletvsimulator12.1
- WATCHOS_SDK=watchsimulator5.1
- TVOS_SDK=appletvsimulator12.2
- WATCHOS_SDK=watchsimulator5.2
matrix:
- DESTINATION="OS=5.1,name=Apple Watch Series 3 - 42mm" SCHEME="$WATCHOS_FRAMEWORK_SCHEME" SDK="$WATCHOS_SDK" RUN_TESTS="NO" POD_LINT="NO"
- DESTINATION="OS=5.1,name=Apple Watch Series 4 - 44mm" SCHEME="$WATCHOS_FRAMEWORK_SCHEME" SDK="$WATCHOS_SDK" RUN_TESTS="NO" POD_LINT="NO"

- DESTINATION="OS=12.1,name=Apple TV 4K" SCHEME="$TVOS_FRAMEWORK_SCHEME" SDK="$TVOS_SDK" RUN_TESTS="NO" POD_LINT="NO"

- DESTINATION="arch=x86_64" SCHEME="$MACOS_FRAMEWORK_SCHEME" SDK="$MACOS_SDK" RUN_TESTS="NO" POD_LINT="NO"

- DESTINATION="OS=12.1,name=iPhone X" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" RUN_TESTS="NO" POD_LINT="YES"
- DESTINATION="OS=12.1,name=iPhone Xs" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" RUN_TESTS="NO" POD_LINT="YES"

before_install:
- gem install cocoapods --pre --no-rdoc --no-ri --no-document --quiet
- gem install cocoapods --pre --no-document --quiet
script:
- set -o pipefail
- xcodebuild -version
Expand Down
3 changes: 2 additions & 1 deletion Sources/libcmark_gfm/include/cmark-gfm-core-extensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ extern "C" {

#include "cmark-gfm-extension_api.h"
#include "cmark-gfm-extensions_export.h"
#include "config.h"
#include <stdint.h>

CMARK_GFM_EXTENSIONS_EXPORT
Expand All @@ -22,7 +23,7 @@ CMARK_GFM_EXTENSIONS_EXPORT
int cmark_gfm_extensions_get_table_row_is_header(cmark_node *node);

CMARK_GFM_EXTENSIONS_EXPORT
char *cmark_gfm_extensions_get_tasklist_state(cmark_node *node);
bool cmark_gfm_extensions_tasklist_state_is_checked(cmark_node *node);

#ifdef __cplusplus
}
Expand Down
65 changes: 52 additions & 13 deletions Sources/libcmark_gfm/table.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ cmark_node_type CMARK_NODE_TABLE, CMARK_NODE_TABLE_ROW,

typedef struct {
uint16_t n_columns;
int paragraph_offset;
cmark_llist *cells;
} table_row;

Expand Down Expand Up @@ -115,6 +116,7 @@ static table_row *row_from_string(cmark_syntax_extension *self,
int len) {
table_row *row = NULL;
bufsize_t cell_matched = 1, pipe_matched = 1, offset;
int cell_end_offset;

row = (table_row *)parser->mem->calloc(1, sizeof(table_row));
row->n_columns = 0;
Expand All @@ -129,20 +131,32 @@ static table_row *row_from_string(cmark_syntax_extension *self,
pipe_matched = scan_table_cell_end(string, len, offset + cell_matched);

if (cell_matched || pipe_matched) {
cmark_strbuf *cell_buf = unescape_pipes(parser->mem, string + offset,
cell_matched);
cmark_strbuf_trim(cell_buf);

node_cell *cell = (node_cell *)parser->mem->calloc(1, sizeof(*cell));
cell->buf = cell_buf;
cell->start_offset = offset;
cell->end_offset = offset + cell_matched - 1;
while (cell->start_offset > 0 && string[cell->start_offset - 1] != '|') {
--cell->start_offset;
++cell->internal_offset;
cell_end_offset = offset + cell_matched - 1;

if (string[cell_end_offset] == '\n' || string[cell_end_offset] == '\r') {
row->paragraph_offset = cell_end_offset;

cmark_llist_free_full(parser->mem, row->cells, (cmark_free_func)free_table_cell);
row->cells = NULL;
row->n_columns = 0;
} else {
cmark_strbuf *cell_buf = unescape_pipes(parser->mem, string + offset,
cell_matched);
cmark_strbuf_trim(cell_buf);

node_cell *cell = (node_cell *)parser->mem->calloc(1, sizeof(*cell));
cell->buf = cell_buf;
cell->start_offset = offset;
cell->end_offset = cell_end_offset;

while (cell->start_offset > 0 && string[cell->start_offset - 1] != '|') {
--cell->start_offset;
++cell->internal_offset;
}

row->n_columns += 1;
row->cells = cmark_llist_append(parser->mem, row->cells, cell);
}
row->n_columns += 1;
row->cells = cmark_llist_append(parser->mem, row->cells, cell);
}

offset += cell_matched + pipe_matched;
Expand All @@ -161,6 +175,26 @@ static table_row *row_from_string(cmark_syntax_extension *self,
return row;
}

static void try_inserting_table_header_paragraph(cmark_parser *parser,
cmark_node *parent_container,
unsigned char *parent_string,
int paragraph_offset) {
cmark_node *paragraph;
cmark_strbuf *paragraph_content;

paragraph = cmark_node_new_with_mem(CMARK_NODE_PARAGRAPH, parser->mem);

paragraph_content = unescape_pipes(parser->mem, parent_string, paragraph_offset);
cmark_strbuf_trim(paragraph_content);
cmark_node_set_string_content(paragraph, (char *) paragraph_content->ptr);
cmark_strbuf_free(paragraph_content);
parser->mem->free(paragraph_content);

if (!cmark_node_insert_before(parent_container, paragraph)) {
parser->mem->free(paragraph);
}
}

static cmark_node *try_opening_table_header(cmark_syntax_extension *self,
cmark_parser *parser,
cmark_node *parent_container,
Expand Down Expand Up @@ -217,6 +251,11 @@ static cmark_node *try_opening_table_header(cmark_syntax_extension *self,
return parent_container;
}

if (header_row->paragraph_offset) {
try_inserting_table_header_paragraph(parser, parent_container, (unsigned char *)parent_string,
header_row->paragraph_offset);
}

cmark_node_set_syntax_extension(parent_container, self);

parent_container->as.opaque = parser->mem->calloc(1, sizeof(node_table));
Expand Down
15 changes: 9 additions & 6 deletions Sources/libcmark_gfm/tasklist.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,22 @@ typedef enum {
CMARK_TASKLIST_CHECKED,
} cmark_tasklist_type;

// Local constants
static const char *TYPE_STRING = "tasklist";

static const char *get_type_string(cmark_syntax_extension *extension, cmark_node *node) {
return "tasklist";
return TYPE_STRING;
}

char *cmark_gfm_extensions_get_tasklist_state(cmark_node *node) {
if (!node || ((int)node->as.opaque != CMARK_TASKLIST_CHECKED && (int)node->as.opaque != CMARK_TASKLIST_NOCHECKED))
return 0;
bool cmark_gfm_extensions_tasklist_state_is_checked(cmark_node *node) {
if (!node || !node->extension || strcmp(cmark_node_get_type_string(node), TYPE_STRING))
return false;

if ((int)node->as.opaque == CMARK_TASKLIST_CHECKED) {
return "checked";
return true;
}
else {
return "unchecked";
return false;
}
}

Expand Down
2 changes: 1 addition & 1 deletion libcmark_gfm.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "libcmark_gfm"
s.version = "0.29.1"
s.version = "0.29.2"
s.summary = "Swift compatible framework for cmark-gfm"

s.description = <<-DESC
Expand Down

0 comments on commit 0cde9cc

Please sign in to comment.