-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
let less parser support heredoc to convenient multi line string input #2580
Comments
Multiline strings were discussed at #1648, but the context and use-case there were quite different so I'm not closing this as a duplicate. Regardless of above, please learn how to work with GitHub forks and pull-requests (https://help.github.com/categories/collaborating/). Additionally see Contributing Notes. |
Technically this can be achieved with something like: div {
background-image:
svg-cont(
'width:80', 'height:100', `' \
<path d="m100,100"/> \
<path d="m100,50"/> \
... \
'`);
} But this is quite hackish. |
sorry, i am a newer of git, i will learn how to use forks and pull-requests。 i will not use \ to generate muli line string. it is ugly and diffcult to read, you can not figure out whether some space exists behind \。if not support heredoc i'd better to use following style: background-image: svg-cont('width:80', 'height:100',
'<path d="m100,100"/>'
'<path d="m100,50"/>'
); it's not convenient, but it's easy to read. a lot of language support heredoc like ruby(my favorite)、php、C#...。i can not think out why we not support it, it's so easy to support it. |
Backslash continuation is explicit and readable - I can tell that a line is continued by the trailing backslash, and tell that it continues from the previous one if that has a trailing backslash. Bash-style Wouldn't it be cleaner to have the SVG in separate SVG files instead, and to use the build system to inline them into the LESS or the generated CSS during build? There's probably already Gulp/Grunt plugins to do this, and I've used a simple Perl script for it in the past on a project that used Make. |
You don't even need any external tool for this since But I can imagine reasons you don't want it in a separate file: @width: 80;
background-image: svg-cont('width:@{width}', 'height:100',
'<path d="m100,100"/>'
'<path d="m100,50"/>'
); Otherwise you have to put the SVG into the HTML (or invent even more dirty tricks like this) Either way, sure |
Interesting, I didn't know that CSS doesn't get applied to inline SVG [[edit: inline in CSS, not HTML]] Regarding syntax, I think a good golden rule is "look at how Bash does it, and do the opposite". Out of curiosity, can a string span several lines in less?
Also a bad idea, I'm just curious as to whether it works. I'll try it now actually. -- result: doesn't work, thankfully |
It only does if the SVG is inline in the HTML document. You can also reference a CSS file from within the SVG file, so there's no reason that CSS file couldn't be the same LESS-generated one. That might be a cleaner approach. See: https://css-tricks.com/using-svg/ |
I built an interactive SVG-based project a few months ago, I think some browsers/devices had issues with referencing stylesheets from in SVG documents (I recall that IE and mobile Safari were the worst offenders for SVG bugs). An archive of the actual project (ERR online coverage of Estonia's 2015 election) is at: http://hackology.co.uk/elections/ Anyway I'm going off topic here, I'll stop talking about SVG now! |
See the link. Apparently it may work if you embed using |
I tried object / embed / iframe / img. For some methods, the interactivity broke on certain browsers/platforms. With other methods, other stuff broke. Whatever implementation I used in that finished version is based on compromises over browser bugs. iPad Safari was very disappointing during the development of that... |
@battlesnake You're probably right. Browsers still suck at cross-platform SVG, and they'll fail at different times. I did an SVG-based mobile app once. Mobile Safari would grind to a halt because it allocated memory for the total calculated size of SVG, regardless of how much was actually drawn in the document. Mobile IE would crash at random times depending on the number of SVGs and their interactivity. |
first, thanks focus and reply for this issue. i explain why i wanted add this features for less. in the project , i use svg as background image for some icon instead of png image or gif image. because must input some long attriubte such as xmlns when writing svg code, i changed less code and add a function for less to generate svg code, then i can only write svg content and some key attibutes. but in less it is diffcult to input a mulitline string and passed to a javascript function to handle. @seven-phases-max's idea is not convenient enough, because has a lot of svg tag and atttriubtes , i canot write a lot of mixins to map them. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
i want to add a function for less to genererate svg string , the function will be used as follows:
but the parser of the less didn't support heredoc, so it's diffcult to input multi line string. i edit parser.js implements heredoc. so i want my edit can be merged. the following is my edit.
----------------parser.js
The text was updated successfully, but these errors were encountered: