Skip to content

Commit

Permalink
Merge pull request #15 from johnnyhuy/feature/disable-custom-html
Browse files Browse the repository at this point in the history
Feature/disable custom html
  • Loading branch information
johnnyhuy authored Sep 2, 2020
2 parents d28037e + 9569fce commit fc1e5f6
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ggsmark",
"version": "0.1.0",
"version": "0.2.0",
"description": "Markdown extension for the Gentlemen's Gaming Society website.",
"main": "index.js",
"repository": "https://github.com/johnnyhuy/ggsmark.git",
Expand Down
4 changes: 3 additions & 1 deletion src/ggsmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import 'regenerator-runtime/runtime'

export default (text) => {
return unified()
.use(markdown)
.use(markdown, {
blocks: []
})
.use(iframe, {
'www.youtube.com': {
tag: 'iframe',
Expand Down
149 changes: 149 additions & 0 deletions tests/ggsmark.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,111 @@
import dedent from 'dedent'
import ggsmark from '../src/ggsmark'

describe('should have github-like markdown', () => {
test('strikethrough', () => {
// Arrange
let string = dedent`
~~shit~~
`
// Act
let result = ggsmark(string)

// Assert
expect(result).toBe(dedent`
<p><del>shit</del></p>
`)
})

test('auto-link', () => {
// Arrange
let string = dedent`
visit https://ggs.sx/
`
// Act
let result = ggsmark(string)

// Assert
expect(result).toBe(dedent`
<p>visit <a href="https://ggs.sx/">https://ggs.sx/</a></p>
`)
})

test('task lists', () => {
// Arrange
let string = dedent`
- [x] Do work
- [ ] Get a life
- [ ] Open book
`
// Act
let result = ggsmark(string)

// Assert
expect(result).toBe(dedent`
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" checked disabled> Do work</li>
<li class="task-list-item"><input type="checkbox" disabled> Get a life</li>
<li class="task-list-item"><input type="checkbox" disabled> Open book</li>
</ul>
`)
})

test('tables', () => {
// Arrange
let string = dedent`
| Command | Description |
| --- | --- |
| git status | List all new or modified files |
| git diff | Show file differences that haven't been staged |
`
// Act
let result = ggsmark(string)

// Assert
expect(result).toBe(dedent`
<table>
<thead>
<tr>
<th>Command</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>git status</td>
<td>List all new or modified files</td>
</tr>
<tr>
<td>git diff</td>
<td>Show file differences that haven't been staged</td>
</tr>
</tbody>
</table>
`)
})

test('code fencing', () => {
// Arrange
let string = dedent`
\`\`\`ruby
require 'redcarpet'
markdown = Redcarpet.new("Hello World!")
puts markdown.to_html
\`\`\`
`
// Act
let result = ggsmark(string)

// Assert
expect(result).toBe(dedent`
<pre><code class="language-ruby">require 'redcarpet'
markdown = Redcarpet.new("Hello World!")
puts markdown.to_html
</code></pre>
`)
})
})

describe('render soundcloud blocks', () => {
test('single line', () => {
// Arrange
Expand Down Expand Up @@ -86,3 +191,47 @@ describe('render youtube blocks', () => {
expect(result).toMatchSnapshot()
})
})

describe('do not render custom html', () => {
test('span', () => {
// Arrange
let string = dedent`
<span style="color: red">Test</span>
`
// Act
let result = ggsmark(string)

// Assert
expect(result).toBe(dedent`
<p>Test</p>
`)
})

test('heading', () => {
// Arrange
let string = dedent`
<h3 style="color: red">Test</h3>
`
// Act
let result = ggsmark(string)

// Assert
expect(result).toBe(dedent`
<p>Test</p>
`)
})

test('div', () => {
// Arrange
let string = dedent`
<div style="color: red">Test</div>
`
// Act
let result = ggsmark(string)

// Assert
expect(result).toBe(dedent`
<p>Test</p>
`)
})
})

0 comments on commit fc1e5f6

Please sign in to comment.