Comments (15)
yeah I think token.id = token.text.toLowerCase().replace(/\s+/g, '-');
seems fine - according to http://stackoverflow.com/questions/70579/what-are-valid-values-for-the-id-attribute-in-html and https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id there may be compatibility issues with non alphanumeric strings, but I think in practice that won't be an issue and the only "explicitly bad" string is whitespace
it seems slightly better than token.id = token.text.trim().toLowerCase();
because String.prototype.trim()
only removes spaces at the beginning or end of the string
from markdown-styles.
I think the issue is here: https://github.com/mixu/markdown-stream-utils/blob/master/lib/annotate-md-headings.js
token.id = token.text.toLowerCase().replace(/[^\w]+/g, '-');
I'm guessing the Chinese title matches /[^\w]+/g
and hence becomes -. I think I'd need a piece of code that instead takes any non-word characters and converts them into base64 codes that correspond to the relevant (raw) characters since it looks like that's what the Chinese wikipedia does when it converts non-alphanumerics to a header id. Any chance you could write a PR to the repo I mentioned above with a fix (and ideally a test)?
edit: example from Wikipedia: https://zh.wikipedia.org/wiki/1949%E5%B9%B4%E5%AE%89%E5%B7%B4%E6%89%98%E5%9C%B0%E9%9C%87#.E5.9C.B0.E8.B4.A8
from markdown-styles.
I think you are right.
The Chinese title will becomes -
when it matches /[^\w]+/g
.
And I just use encodeURIComponent()
to convert them.
token.id = encodeURIComponent(token.text.toLowerCase());
Now it works.
Another file should be fix in https://github.com/mixu/markdown-styles/blob/master/lib/convert-md.js.
var id = this.options.headerPrefix + encodeURIComponent (raw.toLowerCase());
And I find another issue, the same name heading in the toc cannot auto add -{num}
from markdown-styles.
Hello, I want to display the link raw like ../../#基本理解
,not like ../../#%20%JD%90
.
So I don't want to useencodeURIComponent
to convert, what is your opinion?
token.id = token.text.toLowerCase();
from markdown-styles.
thanks for looking into this! could you also add a test in https://github.com/mixu/markdown-styles/blob/master/test/integration.test.js
with chinese headings (preferably with the same heading used multiple times) so that if I end up making any additional changes at some later time, the test will catch any potential problems with Chinese characters?
from markdown-styles.
Nice!token.id = token.text.toLowerCase().replace(/\s+/g, '-');
is better.
And I will try to add a test in integration.test.js
.
from markdown-styles.
Hello, I think should use .trim()
removes spaces at the beginning or end of the string first, and then try .replace(/\s+/g, '-')
.
Is it right?
from markdown-styles.
sgtm!
from markdown-styles.
I try to add a test in https://github.com/mixu/markdown-styles/blob/master/test/integration.test.js
,and it can pass the test.
it('reads and renders metadata stored in a file with Chinese characters and the same heading used multiple times', function(done) {
var dir = fixture.dir({
'foo.md': [
'title: 你好 世界',
'author: Anonymous',
'----',
'# 世界因我而不同',
'## 世界因我而不同',
'### 世界因我而不同',
'# 一个世界,一个梦想',
'## 一个世界,一个梦想',
'### 世界因我而不同'
].join('\n')
});
var out = fixture.dirname();
mds.render({
input: dir,
output: out,
layout: layoutDir
}, function() {
assert.equal(fs.readFileSync(out + '/foo.html', 'utf8'), [
'"你好 世界" by Anonymous',
'<h1 id="世界因我而不同">世界因我而不同</h1>',
'<h2 id="世界因我而不同-1">世界因我而不同</h2>',
'<h3 id="世界因我而不同-2">世界因我而不同</h3>',
'<h1 id="一个世界,一个梦想">一个世界,一个梦想</h1>',
'<h2 id="一个世界,一个梦想-1">一个世界,一个梦想</h2>',
'<h3 id="世界因我而不同-3">世界因我而不同</h3>\n'
].join('\n'));
done();
});
});
But the generate link in nav-list
is wrong
from markdown-styles.
great, could you update the PRs and I'll see if I can fix that last issue tomorrow?
from markdown-styles.
Thank you, I have already update the PRs.
from markdown-styles.
replace(/\s+/g, '-')
is wrong convert character .
"angular.directive".replace(/\s+/g, '-')
"angular.directive"
"angular directive".replace(/\s+/g, '-')
"angular-directive"
from markdown-styles.
cool thanks! I did a bunch of cleanup, squashed a few commits and added a test for the TOC generation. It should all be fixed if you install v3.1.9
(e.g. npm install -g markdown-styles@latest
).
from markdown-styles.
thanks again, let me know if you run into any further issues!
from markdown-styles.
So great! It works! Thank you very much.
from markdown-styles.
Related Issues (20)
- tables look unreadble in the default mixu-bootstrap-2col layout
- File contents deleted HOT 1
- Markdown files with UTF8 with BOM can lead to incorrect renedering
- Links and special characters
- how to highlight another language
- Add support for maths mode? HOT 2
- Generated HTML has self-closing tags
- Hide render console message?
- github style: Bold not preserved with code
- Change output html filename?
- GitHub style ignores “text” code block formatting HOT 1
- `Could not parse metadata from` by adding 3+ dashes
- Current project status HOT 3
- Help please for any feature to highlight some lines of code ?
- When running from a batch file, lines below `generate-md` cannot execute HOT 1
- GitHub dark theme
- hrefs in toc faulty
- Local links are rendered incorrectly
- Feature Request: use globbing for --input
- npm audit vulnerabilities
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from markdown-styles.