<scriptlet>

<implements type='automation'>
	<method name='OpenTextFile'/>
	<property name='ShowConsole'/>
	<property name='ReadOnly'/>
	<property name='TextType'/>
	<property name='Arguments'/>
</implements>

<script language='vbs'>
Option Explicit

Const ShowConsole = 0
Const ReadOnly = True
Const TextType = "xml"

Const MsxmlProgID = "Msxml2.DOMDocument.6.0"
Const TidyCmdLine = """%WinMergeRoot%\tidy.exe"" -xml --char-encoding raw -indent --indent-attributes yes --tab-size 4 --indent-spaces 4 -wrap 0"

Dim sh
Set sh = CreateObject("WScript.Shell")

Function LoadXml(path)
	Dim xml
	Set LoadXml = Nothing
	If IsEmpty(path) Then Exit Function
	Set xml = CreateObject(MsxmlProgID)
	path = Replace(path, "\\?\UNC\", "\\")
	path = Replace(path, "\\?\", "")
	If xml.load(path) Then Set LoadXml = xml
End Function

Function OpenTextFile(path)
	Dim doc, xslt, tidy, transform, options
	If Not IsEmpty(Arguments) Then Execute Arguments
	Set doc = Nothing
	Set xslt = LoadXml(transform)
	If Not xslt Is Nothing Then Set doc = LoadXml(path)
	If Not doc Is Nothing Then
		Set tidy = sh.Exec(TidyCmdLine & " " & options)
		tidy.StdIn.Write doc.transformNode(xslt)
	Else
		Set tidy = sh.Exec(TidyCmdLine & " " & options & " """ & path & """")
	End If
	Set OpenTextFile = tidy.StdOut
End Function
</script>
</scriptlet>
