Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Commit

Permalink
[removed] transformer support from the Markup class; updated the li…
Browse files Browse the repository at this point in the history
…brary definition file and the project dependencies
  • Loading branch information
thealjey committed Mar 4, 2016
1 parent 5d64054 commit 4e525a9
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 448 deletions.
79 changes: 8 additions & 71 deletions docs/Markup.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ <h2>

<hr>
<dt>
<h4 class="name" id="Markup"><span class="type-signature"></span>new Markup(transformers)</h4>
<h4 class="name" id="Markup"><span class="type-signature"></span>new Markup()</h4>


</dt>
Expand All @@ -99,7 +99,6 @@ <h4 class="name" id="Markup"><span class="type-signature"></span>new Markup(tran
<div class="description">
<p>Allows to easily and efficiently convert text from Markdown to HTML and from HTML to a collection of React Elements
that can be used directly in a JSX expression.</p>
<p>Whenever an HTML string is involved, runs it through an array of Transformer functions.</p>
</div>


Expand All @@ -109,68 +108,6 @@ <h4 class="name" id="Markup"><span class="type-signature"></span>new Markup(tran



<h5>Parameters:</h5>


<table class="params table table-striped">
<thead>
<tr>

<th>Name</th>


<th>Type</th>


<th>Argument</th>




<th class="last">Description</th>
</tr>
</thead>

<tbody>


<tr>

<td class="name"><code>transformers</code></td>


<td class="type">


<span class="param-type"><a href="global.html#Transformer">Transformer</a></span>




</td>


<td class="attributes">





&lt;repeatable><br>

</td>




<td class="description last"><p>transformers to initialize with</p></td>
</tr>


</tbody>
</table>




<dl class="details">
Expand Down Expand Up @@ -208,7 +145,7 @@ <h5>Parameters:</h5>
<ul class="dummy">
<li>
<a href="Markup.js.html">Markup.js</a>,
<a href="Markup.js.html#sunlight-1-line-35">line 35</a>
<a href="Markup.js.html#sunlight-1-line-34">line 34</a>
</li>
</ul>
</dd>
Expand Down Expand Up @@ -386,7 +323,7 @@ <h5>Parameters:</h5>
<ul class="dummy">
<li>
<a href="Markup.js.html">Markup.js</a>,
<a href="Markup.js.html#sunlight-1-line-189">line 189</a>
<a href="Markup.js.html#sunlight-1-line-170">line 170</a>
</li>
</ul>
</dd>
Expand Down Expand Up @@ -576,7 +513,7 @@ <h5>Parameters:</h5>
<ul class="dummy">
<li>
<a href="Markup.js.html">Markup.js</a>,
<a href="Markup.js.html#sunlight-1-line-244">line 244</a>
<a href="Markup.js.html#sunlight-1-line-225">line 225</a>
</li>
</ul>
</dd>
Expand Down Expand Up @@ -766,7 +703,7 @@ <h5>Parameters:</h5>
<ul class="dummy">
<li>
<a href="Markup.js.html">Markup.js</a>,
<a href="Markup.js.html#sunlight-1-line-267">line 267</a>
<a href="Markup.js.html#sunlight-1-line-248">line 248</a>
</li>
</ul>
</dd>
Expand Down Expand Up @@ -954,7 +891,7 @@ <h5>Parameters:</h5>
<ul class="dummy">
<li>
<a href="Markup.js.html">Markup.js</a>,
<a href="Markup.js.html#sunlight-1-line-304">line 304</a>
<a href="Markup.js.html#sunlight-1-line-271">line 271</a>
</li>
</ul>
</dd>
Expand Down Expand Up @@ -1142,7 +1079,7 @@ <h5>Parameters:</h5>
<ul class="dummy">
<li>
<a href="Markup.js.html">Markup.js</a>,
<a href="Markup.js.html#sunlight-1-line-320">line 320</a>
<a href="Markup.js.html#sunlight-1-line-287">line 287</a>
</li>
</ul>
</dd>
Expand Down Expand Up @@ -1330,7 +1267,7 @@ <h5>Parameters:</h5>
<ul class="dummy">
<li>
<a href="Markup.js.html">Markup.js</a>,
<a href="Markup.js.html#sunlight-1-line-336">line 336</a>
<a href="Markup.js.html#sunlight-1-line-303">line 303</a>
</li>
</ul>
</dd>
Expand Down
39 changes: 3 additions & 36 deletions docs/Markup.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,14 @@ <h1 class="page-title">Source: Markup.js</h1>
<pre
class="sunlight-highlight-javascript linenums">/* @flow */

import type {CheerioNode, CheerioElement, Transformer} from './typedef';
import type {CheerioNode, CheerioElement} from './typedef';
import {load} from 'cheerio';
import {createElement} from 'react';
import marked from 'marked';
import reject from 'lodash/reject';
import map from 'lodash/map';
import transform from 'lodash/transform';
import has from 'lodash/has';
import reduce from 'lodash/reduce';
import flattenDeep from 'lodash/flattenDeep';
import isString from 'lodash/isString';
import trim from 'lodash/trim';
Expand Down Expand Up @@ -113,31 +112,13 @@ <h1 class="page-title">Source: Markup.js</h1>
* Allows to easily and efficiently convert text from Markdown to HTML and from HTML to a collection of React Elements
* that can be used directly in a JSX expression.
*
* Whenever an HTML string is involved, runs it through an array of Transformer functions.
*
* @class Markup
* @param {...Transformer} transformers - transformers to initialize with
* @example
* import {Markup} from 'webcompiler';
*
* const mark = new Markup();
*/
export class Markup {
/**
* an array of Transformer functions
*
* @member {Array&lt;Transformer>} transformers
* @memberof Markup
* @private
* @instance
*/
transformers: Array&lt;Transformer>;

/** @constructs */
constructor(...transformers: Array&lt;Transformer>) {
this.transformers = transformers;
}

/**
* Convert the CSS style key to a JSX style key
*
Expand Down Expand Up @@ -364,20 +345,6 @@ <h1 class="page-title">Source: Markup.js</h1>
return Markup.childrenToJSX(lines.toArray());
}

/**
* Runs the html string through an array of Transformer functions
*
* @memberof Markup
* @instance
* @private
* @method transform
* @param {string} html - an arbitrary HTML string
* @return {string} a transformed string
*/
transform(html: string): string {
return reduce(this.transformers, (result, transformer) => transformer(result), html);
}

/**
* Converts an arbitrary HTML string to an array of React Elements
*
Expand All @@ -391,7 +358,7 @@ <h1 class="page-title">Source: Markup.js</h1>
*/
htmlToJSX(html: string = ''): Array&lt;any> {
html = trim(html);
return html ? Markup.childrenToJSX(load(this.transform(html)).root().toArray()[0].children) : [];
return html ? Markup.childrenToJSX(load(html).root().toArray()[0].children) : [];
}

/**
Expand All @@ -407,7 +374,7 @@ <h1 class="page-title">Source: Markup.js</h1>
*/
markdownToHTML(markdown: string = ''): string {
markdown = trim(markdown);
return markdown ? trim(this.transform(Markup.markdownToUnwrappedHTML(markdown))) : '';
return markdown ? Markup.markdownToUnwrappedHTML(markdown) : '';
}

/**
Expand Down
Loading

0 comments on commit 4e525a9

Please sign in to comment.