Ver Mensaje Individual
  #4 (permalink)  
Antiguo 26/08/2016, 03:26
OdooPlay
 
Fecha de Ingreso: abril-2016
Mensajes: 4
Antigüedad: 8 años
Puntos: 0
Respuesta: reemplazar estilos CSS en dependencia de sus propiedades

Solucionado!
concretamente este script puedes usarlo cuando exportes desde indesign, pues Indesign tras la exportación los eBooks no se ven correctamente.
Ten encuenta:

1º lo he testeado desde el terminal de Mac
2º el ebook cuando lo descomprimes tiene la siguiente roota:
./ePub/OEBPS/css/idGeneratedStyles.css

3º el archivo css original tras exportarlo de indesign se llama:
idGeneratedStyles.css

4º Tu simplemente tendrías que sustituir los nombres de tus stylos por los que pone abajo, por ejemplo:
en lugar de:
if grep -qr L0-R0-I4 $f; then

pondrías:
if grep -qr MI_ESTILO_CSS $f; then


5º en este script se modifica solo el margin-left, margin-right y text-indent, pero tu puedes escoger las propiedades que desees.

6º el script simplemente se encargará de:
- dividir todo tu CSS en archivos,
- eliminar las propiedades margin-left, margin-right y text-indent
- reemplazar el signo } por tus propiedades correctas.

7º Después si lo deseas también puedes eliminar todos los archivos CSS que se han creado y juntarlos todos en 1, que se debe llamar idGeneratedStyles.css.
Haciendo esto:

Código BASH:
Ver original
  1. ############
  2. # Delete the original CSS
  3. rm ./ePub/OEBPS/css/idGeneratedStyles.css;
  4. # merge the css files
  5. cat ./ePub/OEBPS/css/GeneratedStyles* > ./ePub/OEBPS/css/idGeneratedStyles.css;
  6. # If you're using bash (the default shell), the extglob shell option allows you to use an extended pattern matching syntax.
  7. shopt -s extglob
  8. #remove all files except the idGeneratedStyles.css
  9. rm -r ./ePub/OEBPS/css/!(idGeneratedStyles.css)
  10.  
  11. sudo chown -Rv root ./ePub
  12. chmod -R 777 ./ePub


8º También puedes eliminar lineas concretas de CSS:
Código BASH:
Ver original
  1. # DELETE CSS LINES. It´s optional. Delete specific lines creating a temporally file, from your CSS for show the pictures with a right size on devices
  2. for x in ./ePub/OEBPS/css/idGeneratedStyles.css;
  3. do
  4. sed '2257,2258d' <"$x" >"$x.tmp"
  5. mv "$x.tmp" "$x"
  6. done
  7. for x in ./ePub/OEBPS/css/idGeneratedStyles.css;
  8. do
  9. sed '2271,2272d' <"$x" >"$x.tmp"
  10. mv "$x.tmp" "$x"
  11. done




Bueno tras esta descripción aqui, esta el código:


Código BASH:
Ver original
  1. #!/bin/bash
  2.  
  3. #####################################################################################
  4. ###START### MODIFY ALL BLEEDING STYLES FOR NICE APPEARANCE ON EPUB AND MOBI #########
  5. #####################################################################################
  6. # Split all the CSS styles from the Adobe Indesign into a separate files
  7. cat ./ePub/OEBPS/css/idGeneratedStyles.css | (
  8. I=0;
  9. echo "">./ePub/OEBPS/css/GeneratedStyles0;
  10. while read line;
  11. do
  12. echo $line >> ./ePub/OEBPS/css/GeneratedStyles$I;
  13. if [ "$line" == '}' ];
  14. then I=$[I+1];
  15. echo "" > ./ePub/OEBPS/css/GeneratedStyles$I;
  16. fi
  17. done;
  18. )
  19.  
  20. sudo chown -Rv root ./ePub/OEBPS/css/*
  21. chmod -R 777 ./ePub/OEBPS/css/*
  22. for f in `ls ./ePub/OEBPS/css/GeneratedStyles*` ; do
  23. ############
  24. if grep -qr L0-R0-I4 $f; then
  25.        
  26. perl -i -ne'/margin-left/ or print' $f;
  27. perl -i -ne'/margin-right/ or print' $f;
  28. perl -i -ne'/text-indent/ or print' $f;
  29.  
  30. #add the right bledding
  31. perl -pi -w -e 's#}#margin-left:0;margin-right:0;text-indent:1em;\}#g;' $f
  32. echo "working on css file $I %";
  33. fi
  34.  
  35. ############
  36. if grep -qr L0-R0-I5 $f; then
  37. #delete the bad bleeding
  38. perl -i -ne'/margin-left/ or print' $f;
  39. perl -i -ne'/margin-right/ or print' $f;
  40. perl -i -ne'/text-indent/ or print' $f;
  41.  
  42. #add the right bledding
  43. perl -pi -w -e 's/}/margin-left:0;margin-right:0;text-indent:1em;\}/g' $f
  44. echo "working on css file $f %";
  45. fi;
  46.  
  47. ############
  48. if grep -qr L0-R0-I3 $f; then
  49. #delete the bad bleeding
  50. perl -i -ne'/margin-left/ or print' $f;
  51. perl -i -ne'/margin-right/ or print' $f;
  52. perl -i -ne'/text-indent/ or print' $f;
  53.  
  54. #add the right bledding
  55. perl -pi -w -e 's/}/margin-left:0;margin-right:0;text-indent:1em;\}/g;' $f
  56. echo "working on css file $f %";
  57. fi;
  58. ############
  59. if grep -qr L0-R0-I5 $f; then
  60. #delete the bad bleeding
  61. perl -i -ne'/margin-left/ or print' $f;
  62. perl -i -ne'/margin-right/ or print' $f;
  63. perl -i -ne'/text-indent/ or print' $f;
  64.  
  65. #add the right bledding
  66. perl -pi -w -e 's/}/margin-left:0;margin-right:0;text-indent:1em;\}/g' $f
  67. echo "working on css file $f %";
  68. fi;
  69.  
  70. ############
  71. if grep -qr L6-R0-I-4 $f; then
  72. #delete the bad bleeding
  73. perl -i -ne'/margin-left/ or print' $f;
  74. perl -i -ne'/margin-right/ or print' $f;
  75. perl -i -ne'/text-indent/ or print' $f;
  76.  
  77. #add the right bledding
  78. perl -pi -w -e 's/}/margin-left:0;margin-right:0;text-indent:1em;\}/g;' $f
  79. echo "working on css file $f %";
  80. fi;
  81. ############
  82. if grep -qr L6-R6-I0 $f; then
  83. #delete the bad bleeding
  84. perl -i -ne'/margin-left/ or print' $f;
  85. perl -i -ne'/margin-right/ or print' $f;
  86. perl -i -ne'/text-indent/ or print' $f;
  87.  
  88. #add the right bledding
  89. perl -pi -w -e 's/}/margin-left:0;margin-right:0;text-indent:1em;\}/g' $f
  90. echo "working on css file $f %";
  91. fi;
  92.  
  93. ############
  94. if grep -qr L6-R6-I3 $f; then
  95. #delete the bad bleeding
  96. perl -i -ne'/margin-left/ or print' $f;
  97. perl -i -ne'/margin-right/ or print' $f;
  98. perl -i -ne'/text-indent/ or print' $f;
  99.  
  100. #add the right bledding
  101. perl -pi -w -e 's/}/margin-left:0;margin-right:0;text-indent:1em;\}/g;' $f
  102. echo "working on css file $f %";
  103. fi;
  104. ############
  105. if grep -qr L14-R4-I-5 $f; then
  106. #delete the bad bleeding
  107. perl -i -ne'/margin-left/ or print' $f;
  108. perl -i -ne'/margin-right/ or print' $f;
  109. perl -i -ne'/text-indent/ or print' $f;
  110.  
  111. #add the right bledding
  112. perl -pi -w -e 's/}/margin-left:0;margin-right:0;text-indent:1em;\}/g;' $f
  113. echo "working on css file $f %";
  114. fi;
  115. ############
  116. if grep -qr CHAPTER_eBook_03-Biblio-entry---2-lines-List-1-to-9---EBOOK $f; then
  117. #delete the bad bleeding
  118. perl -i -ne'/margin-left/ or print' $f;
  119. perl -i -ne'/margin-right/ or print' $f;
  120. perl -i -ne'/text-indent/ or print' $f;
  121.  
  122. #add the right bledding
  123. perl -pi -w -e 's/}/margin-left:0;margin-right:0;text-indent:1em;\}/g' $f
  124. echo "working on css file $f %";
  125. fi;
  126.  
  127. ############
  128. if grep -qr CHAPTER_eBook_03-Biblio-entry---subtitle-List-1-to-9---EBOOK $f; then
  129. #delete the bad bleeding
  130. perl -i -ne'/margin-left/ or print' $f;
  131. perl -i -ne'/margin-right/ or print' $f;
  132. perl -i -ne'/text-indent/ or print' $f;
  133.  
  134. #add the right bledding
  135. perl -pi -w -e 's/}/margin-left:0;margin-right:0;text-indent:1em;\}/g;' $f
  136. echo "working on css file $f %";
  137. fi;
  138. done;
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145. ###END### MODIFY ALL BLEEDING STYLES FOR NICE APPEARANCE ON EPUB AND MOBI #########
  146. #####################################################################################

Última edición por OdooPlay; 26/08/2016 a las 03:35 Razón: añado código extra muy util para el interesado