left menu mob button

Thanks to everyone who said "thank you" by clicking the link:

Олег Е.
(23.12.2020):

За полезные скрипты и с Новым годом!

Фёдор Х.
(22.12.2020):

Большое спасибо!

Дмитрий
(20.06.2020):

За скрипт для работы с таблицами в Индизайне.


New Video on YouTube:

You will never find time for anything. If you want time, you must make it. (Charles Buxton)


Comments

Admin
(12.01.2021 21:40):

Виха, скрипт надо поместить в папку "startup scripts" и перезапустить InDesign. В меню "Таблица" появится пункт меню "Точное выравнивание". Также, если выделить таблицу (либо её фрагмент) и правой кнопкой вызвать контекстное меню, там также будет этот пункт меню. Если Вы всё это проделали, и ничего не получилось, я смогу с Вами связаться и помочь, например, через Team Viewer или другим удобным для Вас способом.

(Exact Table Alignment)

Виха
(12.01.2021 16:22):

Под 16 версией вообще не запускается

(Exact Table Alignment)

Admin
(12.10.2020 20:18):

Galeb, for example: forum.rudtp.ru/threads/scriptpalette.75192/

(Interface for Typical Operations)

Only The Necessary Information

(series of articles):

Export From InDesign to HTML: How to Tag Character Styles

InDesign allows you to retain local text formatting when exporting to html, due to the fact that you can set the necessary html tags and classes in the style parameters (both paragraph and character styles).

With the paragraph styles, everything is more or less simple: there are six standard tags for headings (<h1> — <h6>), and one for the main text (<p>). If the paragraph requires specific formatting, you can specify the appropriate CSS class in the style parameters. In general, there is nothing interesting: just specify the tag and class in the style parameters, format the CSS, and get the result.

parstyle_html_tag.png

Much more interesting is the case with local formatting, which the text gets through character styles. HTML designers are aware that for each of the main types of formatting there is a different tag in html (and for some types, these is more than one):

  • bold: <b>, <strong>;
  • italic: <i>, <em>;
  • underline: <u>;
  • superscript: <sup>;
  • subscript: <sub>.

charstyle_html_tag.png

You can find out about the difference in similar formatting tags and the correctness of their use in html markup on specialized sites. The right to decide which tags to use, and instead of which to use CSS styles (for example, <span class = "Bold">), does not always belong to the coder, who often only needs to provide the content strictly in the form and with the markup, with which this site is configured.

Problems, in this case, arise when the text in InDesign has "mixed" formatting (Bold Italic, Italic Underline, Bold Italic Superscript, etc.), and, in html, it is required to export it wrapped in tags: <strong><i> </i></strong>, <i><u> </u></i>, etc. Through the standard export procedure, we can only get classes from the program:

charstyle_html_class2.png

There can be two solutions here. First: in some html-editor, prepare a series of auto-replacements, with the help of which you process the html-files received from InDesign one-by-one each time, simultaneously clearing them from different "garbage", such as <div class = "x- -------------- "> and so forth.

The second solution is to write a script.

In this case, we will need the script "Preptext.jsx" (by Theunis DeJong, aka "Jongware") as an auxiliary software. It searches for local formatting in the selected story, creates corresponding character styles (if they are not created) and applies them to the text.

preptext.png

As we can see, styles get names according to a certain algorithm. And the presence of an algorithm is always a good opportunity to automate something.

First we turn to the story in which the cursor is positioned, and get ranges of text styles (that is, sections that differ in format from neighboring sections):

var doc = app.activeDocument;
var sel = doc.selection[0].parentStory.textStyleRanges;

Now, we will create an array of correspondences of the basic formatting types in InDesign to the basic html-tags, focusing on the names of the character styles created by the "preptext.jsx" script:

var arr = [];
arr ["Bold"] = "strong";
arr ["Italic"] = "i";
arr ["Underline"] = "u";
arr ["Super"] = "sup";
arr ["Sub"] = "sub";

Now, we will open a cycle, in which we will sort through the style ranges of the text we have obtained. Since we have to change the content of the story, we will start the cycle from the end:

for (i = sel.length-1; i >= 0; i--){

Check whether any character style is applied to the current text section:

	if (sel[i].appliedCharacterStyle.index != 0){

If it is, take its name and extract all words from it, separated by spaces:

	var t = sel[i].appliedCharacterStyle.name.split(" "); 
	/*
	For example, if the name of style is "Bold Italic + Underline",
	than array t gets content: ["Bold", "Italic", "+", "Underline"]
	*/

Now, let’s take all the elements of the array one by one, add the corresponding html tags to the each section of the text, and close the brackets of the condition and the loop:

	for (j = 0; j < t.length; j++){
		if (t[j]!="+"){ // Cut the unnecessary us "plus" (no need to process it)
			try{
				sel[i].contents = "<" + arr[t[j]] + ">" + sel[i].contents + "</" + arr[t[j]] + ">";
				}
			catch(e){
				}
			}
		}
	}
}

Complete code:

var doc = app.activeDocument;
var sel = doc.selection[0].parentStory.textStyleRanges;
var arr = [];
arr ["Bold"] = "strong";
arr ["Italic"] = "i";
arr ["Underline"] = "u";
arr ["Super"] = "sup";
arr ["Sub"] = "sub";


for (i = sel.length-1; i >= 0; i--){
	if (sel[i].appliedCharacterStyle.index != 0){
		var t = sel[i].appliedCharacterStyle.name.split(" ");
		for (j = 0; j < t.length; j++){
			if (t[j]!="+"){
				try{
					sel[i].contents = "<" + arr[t[j]] + ">" + sel[i].contents + "</" + arr[t[j]] + ">";
					}
				catch(e){
					}
				}
			}
		}
	}

As a result of applying the script to the selected story, we get the following content:

scriptRes.png

Now it can be copied and pasted into the html-code blank:

html-editor.png

And you can, for example, export, but not directly to html (because in this case all tag brackets, all quotes and ampersands will be converted to special html characters), but as plain text, manually specifying the html file type, however:

exportAsTextToHTML.png

exportAsTextToHTML_pref.png

REMEMBER that the script should be tested on a copy of a story, and it is advisable to save the publication beforehand so that, in case of unsatisfactory results, you could restore the original data by selecting the Restore command from the File menu.

In the next article, we will teach the script to arrange paragraph tags with classes as well, and also "attach" an html-header with a footer to the text, and get a full-featured html-file, absolutely "clean", containing only the markup we need.

No comments.

Leave a comment:

Name*:
E-mail*:
Comment text*:
Security code*: