Created
February 11, 2016 21:55
-
-
Save bijanebrahimi/8f0b4fee1a96de79f663 to your computer and use it in GitHub Desktop.
a bash script to convert pygment css styles to odt style xml format.
This file contains hidden or 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
#!/bin/sh | |
CSS=$1 | |
read -r -d '' SNIPPET << EOM | |
<style:style style:name="codehilite" style:family="paragraph" style:parent-style-name="Standard" style:master-page-name=""> | |
<loext:graphic-properties draw:fill="solid" draw:fill-color="\2" draw:fill-image-width="0in" draw:fill-image-height="0in"\/> | |
<style:paragraph-properties fo:margin-left="0in" fo:margin-right="0in" fo:orphans="0" fo:widows="0" fo:text-indent="0in" style:auto-text-indent="false" style:page-number="auto" fo:background-color="\2" fo:padding="0.0201in" fo:border="0.06pt solid \2" fo:keep-with-next="auto" style:snap-to-layout-grid="false" style:writing-mode="page"> | |
<style:tab-stops\/> | |
<\/style:paragraph-properties> | |
<style:text-properties fo:color="\1" fo:text-shadow="none" style:text-blinking="false" style:font-size-asian="10.5pt"\/> | |
<\/style:style> | |
<style:style style:name="codehilite" style:family="text"> | |
<style:text-properties style:shadow="none"\/> | |
<\/style:style> | |
EOM | |
CODE=`echo ${SNIPPET} | tr '\n' "\\n"` | |
cat $1 > output | |
sed -i "s/color:red/color:#FF0000/g" output | |
sed -i "s/color:purple/color:#800080/g" output | |
sed -i "s/color:gray/color:#808080/g" output | |
sed -i "s/color:white/color:#FFFFFF/g" output | |
sed -i "s/.codehilite code, .codehilite pre{color:\(#[0-9a-fA-F]*\);background-color:\(#[0-9a-fA-F]*\)}/$CODE/g" output | |
sed -i "s/\.codehilite \.\(.*\){/<style:style style:name=\"\1\" style:family=\"text\" style:parent-style-name=\"codehilite\">\n <style:text-properties /g" output | |
sed -i "s/background-color:#\([0-9a-fA-F]*\)/fo:background-color=\"#\1\"/g" output | |
sed -i "s/color:#\([0-9a-fA-F]*\)/fo:color=\"#\1\"/g" output | |
sed -i "s/font-weight:bold/fo:font-weight=\"bold\"/g" output | |
sed -i "s/font-style:italic/fo:font-style=\"italic\"/g" output | |
sed -i "s/border: 1px solid \(#[0-9a-fA-F]*\)/fo:border=\"0.06pt solid \1\"/g" output | |
sed -i "s/}/\/>\n<\/style:style>/g" output | |
sed -i "s/;/ /g" output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment