Skip to content

Commit

Permalink
SWC-3000: eat center row character syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
jay-hodgson committed Apr 12, 2016
1 parent b144050 commit 2b2f462
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 6 deletions.
18 changes: 16 additions & 2 deletions dist/markdown-it-synapse-table.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*! markdown-it-synapse-table 1.0.3 https://github.com/jay-hodgson/markdown-it-synapse-table @license MIT */(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.markdownitSynapseTable = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
/*! markdown-it-synapse-table 1.0.4 https://github.com/jay-hodgson/markdown-it-synapse-table @license MIT */(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.markdownitSynapseTable = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
// Process '## headings'

'use strict';

module.exports = function synapse_table_plugin(md) {
var tableClassStartRE, tableClassEndRE;
var tableClassStartRE, tableClassEndRE, centerStartRE, centerEndRE;
function getLine(state, line) {
var pos = state.bMarks[line] + state.blkIndent, max = state.eMarks[line];

Expand Down Expand Up @@ -71,6 +71,14 @@ module.exports = function synapse_table_plugin(md) {
tableClassEndRE = new RegExp('^\\s*[|]{1}}\\s*');
}

if (!centerStartRE) {
centerStartRE = new RegExp('^\s*[-]{1}[>]{1}.*');
}

if (!centerEndRE) {
centerEndRE = new RegExp('.*[<]{1}[-]{1}\s*$');
}

// look for optional class definition start, like '{| class="border"'
if (tableClassStartRE.test(lineText)) {
// this table definition includes class names, so the start marker is {| and end marker will be |}
Expand All @@ -97,6 +105,7 @@ module.exports = function synapse_table_plugin(md) {
if (lineText.indexOf('|') === -1 && !isSpecialSyntaxTable) {
return false;
}

// has a '|'. If it looks like there is math on this line, skip it.
if (lineText.indexOf('$$') !== -1) {
return false;
Expand Down Expand Up @@ -175,6 +184,11 @@ module.exports = function synapse_table_plugin(md) {
columns = escapedSplit(lineText.replace(/^\||\|$/g, ''));

token = state.push('tr_open', 'tr', 1);
// if line starts with -> and ends with <-, then eat these characters (SWC-3000)
if (centerStartRE.test(columns[0]) && centerEndRE.test(columns[columnCount - 1])) {
columns[0] = columns[0].substring(columns[0].indexOf('->') + 2);
columns[columnCount - 1] = columns[columnCount - 1].substring(0, columns[columnCount - 1].indexOf('<-'));
}
for (i = 0; i < columnCount; i++) {
token = state.push('td_open', 'td', 1);

Expand Down
4 changes: 2 additions & 2 deletions dist/markdown-it-synapse-table.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'use strict';

module.exports = function synapse_table_plugin(md) {
var tableClassStartRE, tableClassEndRE;
var tableClassStartRE, tableClassEndRE, centerStartRE, centerEndRE;
function getLine(state, line) {
var pos = state.bMarks[line] + state.blkIndent, max = state.eMarks[line];

Expand Down Expand Up @@ -70,6 +70,14 @@ module.exports = function synapse_table_plugin(md) {
tableClassEndRE = new RegExp('^\\s*[|]{1}}\\s*');
}

if (!centerStartRE) {
centerStartRE = new RegExp('^\s*[-]{1}[>]{1}.*');
}

if (!centerEndRE) {
centerEndRE = new RegExp('.*[<]{1}[-]{1}\s*$');
}

// look for optional class definition start, like '{| class="border"'
if (tableClassStartRE.test(lineText)) {
// this table definition includes class names, so the start marker is {| and end marker will be |}
Expand All @@ -96,6 +104,7 @@ module.exports = function synapse_table_plugin(md) {
if (lineText.indexOf('|') === -1 && !isSpecialSyntaxTable) {
return false;
}

// has a '|'. If it looks like there is math on this line, skip it.
if (lineText.indexOf('$$') !== -1) {
return false;
Expand Down Expand Up @@ -174,6 +183,11 @@ module.exports = function synapse_table_plugin(md) {
columns = escapedSplit(lineText.replace(/^\||\|$/g, ''));

token = state.push('tr_open', 'tr', 1);
// if line starts with -> and ends with <-, then eat these characters (SWC-3000)
if (centerStartRE.test(columns[0]) && centerEndRE.test(columns[columnCount - 1])) {
columns[0] = columns[0].substring(columns[0].indexOf('->') + 2);
columns[columnCount - 1] = columns[columnCount - 1].substring(0, columns[columnCount - 1].indexOf('<-'));
}
for (i = 0; i < columnCount; i++) {
token = state.push('td_open', 'td', 1);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "markdown-it-synapse-table",
"version": "1.0.3",
"version": "1.0.4",
"description": "tag for markdown-it markdown parser.",
"main": "index.js",
"keywords": [
Expand Down
20 changes: 20 additions & 0 deletions test/fixtures/synapsetable.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,26 @@ Single column row 1
</div>
.

.
-> | centering | block | table | <-

## and a heading
.
<table>
<tbody>
<tr>
<td></td>
<td>centering</td>
<td>block</td>
<td>table</td>
<td></td>
</tr>
</tbody>
</table>
<h2>and a heading</h2>
.


coverage
.
*~f
Expand Down

0 comments on commit 2b2f462

Please sign in to comment.