Skip to content

Instantly share code, notes, and snippets.

View gregoriopellegrino's full-sized avatar

Gregorio Pellegirno gregoriopellegrino

View GitHub Profile
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from pyvirtualdisplay import Display
import os
from bs4 import BeautifulSoup
import csv
try:
@gregoriopellegrino
gregoriopellegrino / wordpress-epub-allowed-filetypes.php
Created October 23, 2018 13:19
wordpress-epub-allowed-filetypes
// This snippet adds epub mime-type to WordPress' allowed mime-types, so you can upload epub files to WP
// add this to your theme's function.php file
add_filter('upload_mimes', 'eme_myme_types', 1, 1);
function eme_myme_types($mime_types){
$mime_types['epub'] = 'application/epub+zip';
return $mime_types;
}
@gregoriopellegrino
gregoriopellegrino / get_langs_in_html_document.js
Last active August 14, 2019 00:03
Very simple script in jQuery to find all the languages present in an HTML document. Useful for controlling the accessibility of documents. Improvements are welcome. #a11y Made to run from the browser development console
// main lang
if ($("html").get(0).hasAttribute("lang")) {
var main_lang = $("html").attr("lang");
} else {
var main_lang = $("body").attr("lang");
}
console.log("Main language is "+main_lang);
// children lang
var langs = [];
@gregoriopellegrino
gregoriopellegrino / grep_bible_ref.txt
Last active February 14, 2020 15:28
Grep to find and format Bible references in InDesign
(Gen|Es|Lv|Nm|Dt|Gs|Gdc|Rt|1Sam|2Sam|1Re|2Re|1Cr|2Cr|Esd|Ne|Tb|Gdt|Est|1Mac|2Mac|Gb|Sal|Prv|Qo|Ct|Sap|Sir|Is|Ger|Lam|Bar|Ez|Dn|Os|Gl|Am|Abd|Gio|Mic|Mi|Na|Ab|Sof|Ag|Zc|Ml|Mt|Mc|Lc|Gv|At|Rm|1Cor|2Cor|Gal|Ef|Fil|Col|1Ts|2Ts|1Tm|2Tm|Tt|Fm|Eb|Gc|1Pt|2Pt|1Gv|2Gv|3Gv|Gd|Ap)(?= \d)
@gregoriopellegrino
gregoriopellegrino / onix-to-epub.xslt
Last active November 16, 2024 10:55
XSLT to transform ONIX for Books metadata into EPUB metadata
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dc="http://purl.org/dc/elements/1.1/" version="1.0">
<xsl:output method="xml" indent="yes" />
<xsl:template match="Header" />
<xsl:template match="Product">
<!-- dc:identifier https://www.w3.org/TR/epub-33/#sec-opf-dcidentifier -->
<dc:identifier id="bookid">
<xsl:value-of select="concat('urn:isbn:', ProductIdentifier[ProductIDType='15']/IDValue)" />
</dc:identifier>
<meta property="identifier-type" refines="#bookid" scheme="onix:codelist5">15</meta>
@gregoriopellegrino
gregoriopellegrino / force_footnotes_paragraph_style.jsx
Created July 15, 2020 10:46
Script for Adobe InDesign to force the application of paragraph style to footnotes. Useful when importing text from a Word file with local formatting.
// based on https://www.id-extras.com/apply-paragraph-style-footnotes/
paragraph_style = document.footnoteOptions.footnoteTextStyle;
if(paragraph_style.name.charAt(0) == "[") {
alert("Please set a paragraph style for notes in Text > Document footnotes options...");
} else {
document.stories.everyItem().footnotes.everyItem().texts.everyItem().applyParagraphStyle(paragraph_style, true);
}