Home >Web Front-end >JS Tutorial >Javascript example tutorial (19) Using HoTMetal (4)_Basic knowledge

Javascript example tutorial (19) Using HoTMetal (4)_Basic knowledge

WBOY
WBOYOriginal
2016-05-16 19:22:28884browse

HoTMetal uses
javascript


4. How to write document format scripts
The following is an example of a macro: based on the layout of predefined pages Guidelines for formatting documents. In order to observe the effect of this macro, please turn off the Enable Source Layout button and select Tools->Customization from the menu. We first open the application to initialize some global variables. In addition, the name of the macro must be n_Application_Open. The specific code is as follows:


var viewWYSIWYG = 0;

var viewTagsOn = 1;
var viewSource = 2;

]]>


This macro must be called when the HoTMetaL application is opened. Its only purpose is to define three constants that are used in other macros. These constants simply represent the three corresponding HoTMetaL views. By operating the window tags on the left button corner of the HoTMetaL editing window, you can see WYSIWYG (what you see is what you get) view, TagsOn view and source view.
The following macro checks whether the current view is the source view and formats the entire document according to predefined criteria. If the visual is not the source view, a message will be printed and displayed to the user and tell the user to switch views. The code is as follows:




if (ActiveDocument.ViewType == viewSource) {

ActiveDocument.Layout();

}

else {

Application.Alert(" Applying source layout only works in source view.nSwitch to source view and try again.");
}

]]>


It should be noted here that we Two HotMetaL objects have been used here: ActiveDocument and Application. The Layout() method formats the current document. The Alert() method pops up a warning box. Javascript example tutorial (19) Using HoTMetal (4)_Basic knowledgeOkay, now let’s test this macro. Please open a document in HotTMetaL and switch the view to source view. You can select a section in the ProgGuide directory. And turn off the Enable Source Layout button by using Tools->Customization. Then move one of the lines to the right by adding a space, and then call the Macro dialog box from the Tools menu. This will display a list of macros defined in the HotMetaL.mcr file. Then run the Refresh Macros macro to load the new macro you just edited. You will see the Format Current Document macro. You can run it and notice that the indented line returns to its original position. Next we test the Alert() method. Now switch the view to TagsOn view and run the macro again, the dialog box shown in Figure 1 will pop up:




(Figure 1)
Now suppose you want to Format the selected portion of the document. The macro for this request (called Format Current Selection) is very similar to the macro described above (Format Current Document). The only difference between them is: the Layout() method in Format Current Document operates the ActiveDocument object, while the Layout() method in Format Current Selection operates the Selection object:




if (ActiveDocument.ViewType == viewSource) {

Selection.Layout();

} else{

Application. Alert("Applying source layout only works in source view.nSwitch to source view and try again.");
}

]]>
Javascript example tutorial (19) Using HoTMetal (4)_Basic knowledgeLet’s take a good look See how the macro above works. We have indented two lines in the open document. The first line starts with "does not specify" and the other line starts with "referred to in this ma:". As shown in Figure 2:




(Figure 2)
Javascript example tutorial (19) Using HoTMetal (4)_Basic knowledgeNow we select three lines, which include lines starting with "does not specify:" line, as shown in Figure 3:




(Figure 3)
Javascript example tutorial (19) Using HoTMetal (4)_Basic knowledge Finally, we click on the green arrow in the upper left corner of the window, and then the macro The name (Format Current Selection) is displayed in the drop-down menu window, as shown in Figure 4:



(Figure 4) Worth mentioning Yes, the selected lines have been formatted to the original paragraph boundaries. The second line that begins with "referred to in this ma" remains indented but is not formatted.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn