Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

use better escaping in console/new #210

Closed
wants to merge 2 commits into from

2 participants

@sonald

for consistency, extract escape from processor into util for reuse.
make title raw, so special characters remains as it was.

sonald added some commits
@sonald sonald use better escaping in console/new
for consistency, extract escape from processor into util for reuse.
make title raw, so special characters remains as it was.
8b04607
@sonald sonald add missing " and make it lower case c568929
@tommy351 tommy351 closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 21, 2013
  1. @sonald

    use better escaping in console/new

    sonald authored
    for consistency, extract escape from processor into util for reuse.
    make title raw, so special characters remains as it was.
Commits on Jun 22, 2013
  1. @sonald
This page is out of date. Refresh to see the latest.
View
2  assets/init/scaffolds/page.md
@@ -1,3 +1,3 @@
-title: {{ title }}
+title: {{ title|raw }}
date: {{ date }}
---
View
2  assets/init/scaffolds/post.md
@@ -1,4 +1,4 @@
-title: {{ title }}
+title: {{ title|raw }}
date: {{ date }}
tags:
---
View
10 lib/plugins/console/new.js
@@ -6,19 +6,13 @@ var moment = require('moment'),
swig = require('swig'),
extend = require('../../extend'),
util = require('../../util'),
+ escape = util.escape,
file = util.file;
-// http://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words
-var escape = function(str){
- return str.toString().toLowerCase()
- .replace(/\s/g, '-')
- .replace(/\/|\\|\?|%|\*|:|\||"|<|>|\.|#/g, '');
-};
-
// Default scaffolds
var scaffolds = {
post: [
- 'title: {{ title }}',
+ 'title: {{ title|raw }}',
'date: {{ date }}',
'tags:',
'---'
View
16 lib/plugins/processor/index.js
@@ -57,20 +57,8 @@ var getInfoFromFilename = function(str){
return result;
};
-// http://tools.ietf.org/html/rfc3986#section-2.2
-// http://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words
-var escape = function(str){
- var str = str.toString()
- .replace(/\s/g, '-')
- .replace(/:|\/|\?|#|\[|\]|@|!|\$|&|'|\(|\)|\*|\+|,|;|=|\\|%|<|>|\./g, '');
-
- if (filenameCaps == 1){
- str = str.toLowerCase();
- } else if (filenameCaps == 2){
- str = str.toUpperCase();
- }
-
- return str;
+var escape = function(str) {
+ return util.escape(str, filenameCaps);
};
var load = function(file, stat, extname, callback){
View
17 lib/util/escape.js
@@ -0,0 +1,17 @@
+// http://tools.ietf.org/html/rfc3986#section-2.2
+// http://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words
+module.exports = function(str, changeCase){
+ changeCase = changeCase || 0;
+
+ var str = str.toString().toLowerCase()
+ .replace(/\s/g, '-')
+ .replace(/:|\/|\?|#|\[|\]|@|!|\$|&|'|"|\(|\)|\*|\+|,|;|=|\\|%|<|>|\./g, '');
+
+ if (changeCase == 1){
+ str = str.toLowerCase();
+ } else if (changeCase == 2){
+ str = str.toUpperCase();
+ }
+
+ return str;
+};
View
3  lib/util/index.js
@@ -5,5 +5,6 @@ module.exports = {
exec: require('./exec'),
highlight: require('./highlight'),
titlecase: require('./titlecase'),
- Timer: require('./timer')
+ Timer: require('./timer'),
+ escape: require('./escape')
};
Something went wrong with that request. Please try again.