Skip to content

Commit

Permalink
remark-ping: configure it and render in rebber
Browse files Browse the repository at this point in the history
  • Loading branch information
vhf committed Jul 7, 2017
1 parent a926d27 commit c4dd295
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 4 deletions.
4 changes: 3 additions & 1 deletion packages/remark-ping/dist/index.js
Expand Up @@ -20,16 +20,18 @@ function plugin(ctx) {
var username = keep[2] ? keep[2] : keep[1];

if (ctx.pingUsername(username)) {
var url = ctx.userURL(username);
return eat(total)({
type: 'ping',
url: url,
children: [{
type: 'text',
value: username
}],
data: {
hName: 'a',
hProperties: {
href: ctx.userURL(username),
href: url,
class: 'ping'
}
}
Expand Down
4 changes: 3 additions & 1 deletion packages/remark-ping/src/index.js
Expand Up @@ -20,16 +20,18 @@ function plugin (ctx) {
const username = keep[2] ? keep[2] : keep[1]

if (ctx.pingUsername(username)) {
const url = ctx.userURL(username)
return eat(total)({
type: 'ping',
url: url,
children: [{
type: 'text',
value: username
}],
data: {
hName: 'a',
hProperties: {
href: ctx.userURL(username),
href: url,
class: 'ping'
}
}
Expand Down
21 changes: 20 additions & 1 deletion packages/zmarkdown/config.js
@@ -1,3 +1,4 @@
const request = require('sync-request')
const textrApostrophes = require('typographic-apostrophes')
const textrApostrophesForPlurals = require('typographic-apostrophes-for-possessive-plurals')
const textrCopyright = require('typographic-copyright')
Expand Down Expand Up @@ -237,11 +238,29 @@ const defaultConfig = {
math: 'Equation:',
inlineMath: 'Equation:'
}
}
},

ping: {
pingUsername: (username) => {
try {
const result = request(
'HEAD',
`https://zestedesavoir.com/api/membres/exists/?search=${username}`,
{timeout: 300}
)
return result.statusCode === 200
} catch (ex) {
console.error(ex)
return false
}
},
userURL: (username) => `/membres/voir/${username}/`,
},
}

const rebberConfig = {
override: {
ping: require('rebber/dist/types/link'),
emoticon: require('rebber/dist/custom-types/emoticon'),
figure: require('rebber/dist/custom-types/figure'),
sub: require('rebber/dist/custom-types/sub'),
Expand Down
2 changes: 2 additions & 0 deletions packages/zmarkdown/index.js
Expand Up @@ -17,6 +17,7 @@ const remarkIframes = require('remark-iframes')
const remarkKbd = require('remark-kbd')
const remarkMath = require('remark-math')
const remarkNumberedFootnotes = require('remark-numbered-footnotes')
const remarkPing = require('remark-ping')
const remarkSubSuper = require('remark-sub-super')
const remarkTextr = require('./remark-textr')
const remarkTrailingSpaceHeading = require('remark-heading-trailing-spaces')
Expand Down Expand Up @@ -57,6 +58,7 @@ const zmdParser = (config) => {
.use(remarkMath, config.math)
.use(remarkKbd)
.use(remarkNumberedFootnotes)
.use(remarkPing, config.ping)
.use(remarkSubSuper)
.use(remarkTrailingSpaceHeading)

Expand Down
2 changes: 2 additions & 0 deletions packages/zmarkdown/package.json
Expand Up @@ -35,6 +35,7 @@
"remark-parse": "^3.0.1",
"remark-rehype": "^2.0.1",
"remark-sub-super": "^0.0.15",
"sync-request": "^4.1.0",
"textr": "^0.3.0",
"typographic-apostrophes": "^1.1.1",
"typographic-apostrophes-for-possessive-plurals": "^1.0.5",
Expand Down Expand Up @@ -62,6 +63,7 @@
"babelify": "^7.3.0",
"browserify": "^14.4.0",
"chai": "^4.0.2",
"clone": "^2.1.1",
"dedent": "^0.7.0",
"envify": "^4.0.0",
"eslint": "^4.0.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/zmarkdown/test/test.js
@@ -1,4 +1,5 @@
const fs = require('fs')
const clone = require('clone')

const chai = require('chai')
const expect = require('chai').expect
Expand All @@ -14,7 +15,7 @@ const renderString = (config = defaultConfig) => zmarkdown(config).renderString
const renderFile = (config = defaultConfig) => zmarkdown(config).renderFile

const configOverride = (config) => {
const newConfig = JSON.parse(JSON.stringify(defaultConfig))
const newConfig = clone(defaultConfig)
Object.assign(newConfig, config)
return newConfig
}
Expand Down

0 comments on commit c4dd295

Please sign in to comment.