Steve Litt
2017-04-29 05:42:07 UTC
Hi everyone,
My experimentation tells me that life's much easier if I put the <svg/>
element and all it contains in my HTML file, rather than trying to
import it with <img/> or <object/>. So I made the following scripts to
put the <svg> part of a (presumably Inkscape created) SVG file into an
HTML file wherever the following is located:
<div class="token">myfile.svg</div>
Be sure to use doublequotes around "token": These are simple scripts.
Script 1: insertsvg.awk myfile.html
Script 2: justsvg.awk mysvg.svg
Let's say these two Awk files were executable and on the path. In your
myfile.html, place the following line (alone on its line) where you
want the <svg/> element to be inserted:
<div class="token">mysvg.svg</div>
Now, assuming myfile.html and mysvg.svg are both in the current
directory, just do the following:
./insertsvg.svg myfile.html > myfile_complete.html
Now myfile_complete.html no longer has the div.token, but in its place
has the entire <svg/> element from mysvg.svg.
This means when you include your Inkscape built SVGs in HTML files,
theres an easy automated way to do it without having to resort to cut
and paste.
And now for the scripts:
/* ======= insertsvg.awk ==============*/
#!/usr/bin/gawk -We
{printthisline = 1}
/<div\s\s*class="token"\s*>\s*[^<]*\s*<\/div>/{
printthisline = 0
svgfile = \
gensub(/\s*<div\s\s*class="token"\s*>\s*([^<]*)\s*<\/div>\s*/, \
"\\1", "1")
system("./justsvg.awk " svgfile)
}
printthisline == 1 {print}
/* ======= justsvg.awk ==============*/
#!/usr/bin/gawk -We
BEGIN {insvg = 0}
/\s*<svg/ { insvg = 1 }
insvg == 1 { print }
/\s*<\/svg\s*>/ { insvg = 0; exit 0 }
HTH,
SteveT
Steve Litt
April 2017 featured book: Troubleshooting Techniques
of the Successful Technologist
http://www.troubleshooters.com/techniques
My experimentation tells me that life's much easier if I put the <svg/>
element and all it contains in my HTML file, rather than trying to
import it with <img/> or <object/>. So I made the following scripts to
put the <svg> part of a (presumably Inkscape created) SVG file into an
HTML file wherever the following is located:
<div class="token">myfile.svg</div>
Be sure to use doublequotes around "token": These are simple scripts.
Script 1: insertsvg.awk myfile.html
Script 2: justsvg.awk mysvg.svg
Let's say these two Awk files were executable and on the path. In your
myfile.html, place the following line (alone on its line) where you
want the <svg/> element to be inserted:
<div class="token">mysvg.svg</div>
Now, assuming myfile.html and mysvg.svg are both in the current
directory, just do the following:
./insertsvg.svg myfile.html > myfile_complete.html
Now myfile_complete.html no longer has the div.token, but in its place
has the entire <svg/> element from mysvg.svg.
This means when you include your Inkscape built SVGs in HTML files,
theres an easy automated way to do it without having to resort to cut
and paste.
And now for the scripts:
/* ======= insertsvg.awk ==============*/
#!/usr/bin/gawk -We
{printthisline = 1}
/<div\s\s*class="token"\s*>\s*[^<]*\s*<\/div>/{
printthisline = 0
svgfile = \
gensub(/\s*<div\s\s*class="token"\s*>\s*([^<]*)\s*<\/div>\s*/, \
"\\1", "1")
system("./justsvg.awk " svgfile)
}
printthisline == 1 {print}
/* ======= justsvg.awk ==============*/
#!/usr/bin/gawk -We
BEGIN {insvg = 0}
/\s*<svg/ { insvg = 1 }
insvg == 1 { print }
/\s*<\/svg\s*>/ { insvg = 0; exit 0 }
HTH,
SteveT
Steve Litt
April 2017 featured book: Troubleshooting Techniques
of the Successful Technologist
http://www.troubleshooters.com/techniques