Javascript example tutorial (19) Use HoTMetal (4)

Source: Internet
Author: User

Use javascript in HoTMetal

4. How to write a script in the document format

The following is an example of a macro: format the document based on the predefined page layout rules. To observe the macro effect, disable the Enable Source Layout (allow Source program Layout) button. Select Tools> Customization from the menu ). First, open the application to initialize some global variables. In addition, the macro name must be n_Application_Open. The specific code is as follows:

<MACRO name = "On_Application_Open" lang = "JScript"> <! [CDATA [

Var viewWYSIWYG = 0;

Var viewTagsOn = 1;

Var viewSource = 2;

]> </MACRO>

This macro must be called only when the HoTMetaL application is opened. Its sole purpose is to define three constants for other macros. These constants only represent three corresponding HoTMetaL views. You can view the WYSIWYG (WYSIWYG as WYSIWYG) view, TagsOn view, and source program view at the corner of the buttons on the left side of the HoTMetaL editing window.

The following macro checks whether the current view is a source view and formats the entire document according to predefined principles. If the visual view is not the source view, a message is printed and displayed to the user. The Code is as follows:

<MACRO name = "Format Current Document" lang = "JScript" id = "153" desc = "Apply source layout to entire document">

<! [CDATA [

If (ActiveDocument. ViewType = viewSource ){

ActiveDocument. Layout ();

}

Else {

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

}

]> </MACRO>

Note that we have used two HotMetaL objects: ActiveDocument and Application. This Layout () method is used to format the current document. The Alert () method prompts a warning box.
Okay, now let's test this macro. Open a document in HotTMetaL and switch the view to the Source view. You can select a segment in the ProgGuide directory. In addition, Enable Source Layout is disabled by using Tools> Customization. Move one row to the right by adding spaces, and then call the macro dialog box from the tool menu. The macro list defined in the HotMetaL. mcr file is displayed. 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 pay attention to the Indented row to return to its original position. Next we will test the Alert () method. Switch the view to the TagsOn view and run the macro again. The 1 dialog box is displayed:



(Figure 1)

Now suppose you want to format the selected part in the document. The requested Macro (known as Format Current Selection) is similar to the preceding macro (Format Current Document. The difference between them is that in: Format Current Document, the Layout () method is used to operate the ActiveDocument object, while the Layout () method in Format Current Selection is used to operate the Selection object:

<MACRO name = "Format Current Selection" lang = "JScript" id = "53" desc = "Apply source layout to the current selection">

<! [CDATA [

If (ActiveDocument. ViewType = viewSource ){

Selection. Layout ();

} Else {

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

}

]> </MACRO>
Let's take a good look at how the above macro works. We indented two lines in the document we opened. The first line starts with "does not specify", and the other line starts with "referred to in this ma. 2:



(Figure 2)

Now we select three rows. These three rows contain rows starting with "does not specify:", as shown in 3:



(Figure 3)

Finally, click the green arrow in the upper left corner of the window, and then the macro name (Format Current Selection) is displayed in the drop-down menu window, as shown in 4:



(Figure 4)

It is worth mentioning that the selected row has been formatted as the original section boundary. The second line starting with "referred to in this ma" is indented and not formatted.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.