-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: font-stretch doesn't match the regex #56
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/node_modules/ | ||
example*/out/ | ||
example*/node_modules | ||
.*.swp | ||
.*.swo | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Open+Sans:300&subset=cyrillic,cyrillic-ext,greek,greek-ext,latin-ext |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
var gulp = require('gulp'); | ||
var googleWebFonts = require('../'); | ||
|
||
var options = { }; | ||
|
||
gulp.task('fonts', function () { | ||
return gulp.src('./fonts.list') | ||
.pipe(googleWebFonts(options)) | ||
.pipe(gulp.dest('out/fonts')) | ||
; | ||
}); | ||
|
||
gulp.task('default', ['fonts']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "example5", | ||
"version": "0.0.1", | ||
"description": "", | ||
"main": "gulpfile.js", | ||
"scripts": { | ||
"test": "gulp" | ||
}, | ||
"author": "Tingyu Huang", | ||
"license": "ISC" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -236,17 +236,22 @@ function getter(options) { | |
// since Google doesn't put there '.svg' suffix for some reason | ||
// (but does that for other extensions). | ||
var re = new RegExp([ | ||
"\\s*font-family:\\s*'([^']+)';", | ||
"\\s*font-style:\\s*(\\w+);", | ||
"\\s*font-weight:\\s*(\\w+);", | ||
"\\s*src:([^;]*);", | ||
".*(?:unicode-range:([^;]+);)?", | ||
"\\s*font-family:\\s*'(?<family>[^']+)';", | ||
"\\s*font-style:\\s*(?<style>\\w+);", | ||
"\\s*font-weight:\\s*(?<weight>\\w+);", | ||
".*(?:\\s*font-stretch:\\s(?<stretch>[^;]+);)?", | ||
"\\s*src:(?<src>[^;]*);", | ||
".*(?:unicode-range:(?<range>[^;]+);)?", | ||
].join(''), 'm'); | ||
|
||
return formatData.apply(null, block.match(re, 'm')); | ||
|
||
let found = block.match(re, 'm'); | ||
if (found === null) { | ||
throw new Error("faild to match block"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo, "faild" => "failed" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks. It's fixed in #57 . |
||
} | ||
return formatData(found.groups); | ||
|
||
function formatData(block, family, style, weight, src, range) { | ||
function formatData(data) { | ||
const { family, style, weight, stretch, src, range } = data; | ||
var name = [family, style, weight].join('-') + '.' + ext; | ||
var url = src.match(/url\(([^)]+)\)/)[1]; | ||
var locals = src.match(/local\([^)]+\)/g) || []; | ||
|
@@ -257,6 +262,7 @@ function getter(options) { | |
name: name.replace(/\s/g, '_'), | ||
url: url, | ||
locals: locals, | ||
stretch: stretch || 'normal', | ||
range: range || 'U+0-10FFFF' | ||
}; | ||
} | ||
|
@@ -280,6 +286,7 @@ function getter(options) { | |
' font-style: $style;', | ||
' font-weight: $weight;', | ||
' font-display: ' + options.fontDisplayType + ';', | ||
' font-stretch: $stretch;', | ||
' src: $src' + format + ';', | ||
' unicode-range: $range;', | ||
'}' | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the .* really needed?
It would actually be better if this entire "we match everything at once" would go away and we would match the stuff we really need instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A proper parser CSS parser might be useful instead of using Regexes here. I'm open to PRs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The .* is cpoied from the pattern of
unicode-range
. It could help when there are lines betweenfont-weight
andfont-stretch
. I agree that a proper CSS parser would be helpful. This PR is a quick fix.