Python script/Script Python
Convert anchor tags in InDesign HTML file
(correct-html-indesign.py)

Makes absolute anchor links in InDesign HTML file relative to the document before opening with Microsoft Word
Rend les liens d'ancrage absolus d'un fichier HTML InDesign relatifs au document avant de l'ouvrir avec Microsoft Word

[ENGLISH]

Dependencies

This programme was written using the Python programming language.

Before running the script, Python must be installed on the machine.

The script uses Python's REGEX search/replace functions to perform the operations described below.

Script target

This Python script converts the links to anchors in an HTML file generated with InDesign (legacy HTML format) to make them relative to the document when opening the HTML file with Microsoft Word.

Anchors and links generated by InDesign during HTML export are, by default, absolute (i.e. relative to the HTML file saved on the disk). The script allows you to make them relative to the current document; the links to the anchors thus become functional whatever the name or location of the Word file.

The links generated in the HTML/Word file are compatible with the Métopes XML production chain. So when the styled Word file is imported into XMLMind, the links to the anchors are converted into:

<ref target="...">

Applied operations

The script performs the following operations on the file :

Renaming anchor tags

Searching tags…

<a id='...'>

that become:

<a name='...'>

Correcting links to anchors

Searching tags…

<a href="geo-47-5-propre.html#_idTextAnchor007">

that become:

<a href="#_idTextAnchor007">

How it works

         Export the file from InDesign in ‘legacy HTML’ format;

         Run the ‘correct-indd-html-vx.xscript;

         Select the HTML file to convert (the file is not modified);

         The script applies the above operations and saves the HTML file under a new name;

         Open the modified file with Word;

         Save it as DOCX file.

Compatibility

The script is compatible with files exported in Adobe InDesign ‘legacy HTML’ format (all versions).

The script works on both Windows and Mac OS (provided that Python and the corresponding libraries are installed on the machine).

Version

1.4.

 

[FRENCH]

Prérequis

Ce programme a été écrit en utilisant le langage de programme Python.

Avant de lancer le script, il faut donc installer Python sur la machine.

Le script utilise les fonctions de rechercher/remplacer REGEX de Python pour appliquer les opérations décrites ci-dessous.

But du programme

Ce script Python convertit les liens vers les ancres dans un fichier HTML généré depuis InDesign (format HTML hérité) pour les rendre relatifs au document en cours dans Microsoft Word.

Les ancres et les liens générés par InDesign lors de l’export HTML sont absolus (donc relatifs au fichier HTML enregistré sur le disque). Le script permet de les rendre relatifs au document en cours ; les liens vers les ancres deviennent ainsi fonctionnels quel que soit le nom ou l’emplacement du fichier, une fois ouvert avec Word.

Les liens générés dans le fichier HTML/Word sont compatibles avec la chaîne de production XML Métopes. Ainsi, lors de l’import du fichier Word stylé dans XMLMind, les liens vers les ancres sont convertis en balises :

<ref target="...">

Opérations effectuées

Le script applique les opérations suivantes sur le fichier :

Renommage des ancres

Recherche des balises…

<a id='...'>

…qui deviennent :

<a name='...'>

Rectification des liens vers les ancres

Recherche des balises…

<a href="geo-47-5-propre.html#_idTextAnchor007">

…qui deviennent

<a href="#_idTextAnchor007">

Fonctionnement

         Exporter le fichier depuis InDesign au format « HTML hérité » ;

         Lancer le script « correct-indd-html-vx.x » ;

         Sélectionner le fichier HTML à convertir (le fichier n’est pas modifié) ;

         Le script applique les opérations ci-dessus et enregistre le fichier HTML sous un nouveau nom ;

         Ouvrir le fichier HTML modifié avec Word ;

         Enregistrer le fichier au format DOCX.

Compatibilité

Le script est compatible avec les fichiers exportés au format « HTML hérité » d’Adobe InDesign (toutes versions).

Le script fonctionne à la fois sous Windows et sous Mac OS (à condition que Python et les librairies correspondantes soient installées sur la machine).

Version

1.4.