Markdown to HTML: script compatible with WSH - jscript

There's a Markdown-to-HTML converter at Pagedown project (JS script).
My question is: how can I adapt this JS script to WSH (Windows Script Host) usage? I need e.g. js script which can be called by WSH command line:
cscript.exe md_to_html.js c:\test\aa.md
I didn't find such page in google.

Create WSF-file named pagedown.wsf with the following script
<job>
<object id="Stream" progid="Adodb.Stream" /> <!-- utf-8 documents support -->
<script language="jscript" src="Markdown.Converter.js" />
<script language="jscript">
Stream.Charset = 'utf-8';
Stream.Open();
Stream.LoadFromFile(WScript.Arguments.Item(0));
var text = Stream.ReadText();
WSH.Echo(new Markdown.Converter().makeHtml(text))
</script>
</job>
and use it with cscript.exe
cscript //Nologo pagedown.wsf input.md > output.html
In case of troubles with ADODB try to download and install it from here.

Related

Trying to create a handler for .maff files in Linux

MAFF files are simply zip files. I'm trying to create a handler for .maff in linux so that when I click on them or type xdg-open x.maff it will call my handler instead of the default which is to open the directory in nautilus. I created an application-x-maff.xml file that contains:
<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
<mime-type type="application/x-maff">
<comment>maff type</comment>
<magic priority="100">
<match offset="0" type="string" value="PK\x03\x04" />
</magic>
<glob pattern="*.maff"/>
</mime-type>
</mime-info>
and saved in ~/.local/share/mime/packages. Created also a ~/.local/share/applications/maffapplication.desktop that contains
[Desktop Entry]
Type=Application
MimeType=application/x-maff
Name=Maff Handler
Exec=<my home path>/bin/linux/maffHandler
and executed
% update-mime-database ~/.local/share/mime/packages/
% update-desktop-database ~/.local/share/applications
If I do
% gio info x.maff (filtered)
standard::content-type: application/x-maff
standard::fast-content-type: application/x-maff
and if I do
% gio mime application/x-maff
Registered applications:
maffapplication.desktop
Recommended applications:
maffapplication.desktop
everything seems to be right ... but then xdg-open x.maff does not work, still calls nautilus ... worse yet, if I do
% xdg-mime query filetype x.maff
application/zip
I'm sure I'm missing something ... somehow I need to override this association between the .maff file that starts with the same magic as a zip file to no avail ... I tried all kinds of modifications on the xml file, with and without the magic, nothing works
By the way, if I do
% maffHandler x.maff
it works perfectly and opens the maff file in firefox, I'm willing to share the C++ code of that if anyone is interested
Seems that TDE (Trinity Desktop) does not properly set two important environment variables
setenv XDG_CURRENT_DESKTOP KDE
setenv KDE_SESSION_VERSION 5
Once they are set at .login (unfortunately had to log out and login again) xdg- scripts started working properly and recognizing the MIME types. The other problem is that TDE requires that you manually add the association on Control Center -> TDE Components -> File Associations.
After environment variables properly set for my environment and File Associations set, then it all works perfectly. Thanks

WSO2 ESB Can't run Groovy script stored in registry

I'm trying to execute a Groovy script that I'm storing in the WSO2 ESB Local registry. When I do that I'm getting the following error:
ERROR {org.apache.synapse.mediators.bsf.ScriptMediator} - The script engine returned a NoSuchMethodException executing the external groovy script : Value {name ='null', keyValue ='file:Scripts/Groovy/test.groovy'} function mediate {org.apache.synapse.mediators.bsf.ScriptMediator}
java.lang.NoSuchMethodException: No signature of method: com.sun.script.groovy.GroovyScriptEngine.mediate() is applicable for argument types: (org.apache.synapse.mediators.bsf.ScriptMessageContext) values: [org.apache.synapse.mediators.bsf.ScriptMessageContext#716f8a10]
Possible solutions: wait()
If I put the code in-line in the script mediator, everything is running ok.
I've tried to wrap the script code like this <x><![CDATA[...code...]]></x>, as shown in the Using Ruby Scripts for Mediation example:
Sample 353: Using Ruby Scripts for Mediation. I add the groovy-all-2.4.7.jar to ESB_HOME\repository\components\lib too.
How can I run the groovy scripts stored in the registry? What am I doing wrong?
Here is the Groovy Script and the proxy, wiht which I'm testing:
Groovy Script
class Example {
static def DisplayName() {
println("This is how methods work in groovy");
println("This is an example of a simple method");
}
static void main(String[] args) {
DisplayName();
}
}
Proxy service
<proxy name="TestScriptProxy" startOnLoad="true" trace="disable"
transports="http https" xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
<script language="groovy"><![CDATA[println "This is an in-line script";]]></script>
<script function="DisplayName"
key="file:Scripts/Groovy/test.groovy" language="groovy"/>
</inSequence>
<outSequence/>
<faultSequence/>
</target>
</proxy>
ESB version is 5.0.0 running on Windows 10.
If you have the Groovy script in the registry, the source should be the registry path. For example : gov:scripts/Groovy/test.groovy.
If you are referring a file give path relative to ESB_HOME. For example if scripts folder is in ESB_HOME directory, file:scripts/Groovy/test.groovy
First load the script file as below :
<localEntry key="DisplayNameScript" src="file:scripts/Groovy/test.groovy"/>
Now call the function
<script language="groovy" key="DisplayNameScript" function="DisplayName"/>

ckeditor set custom skinpath

I have a problem with the CKEDITOR. I installed it with bower and changed the basepath. So CKEDITOR works.
My problem now is to laod a custom skin, because i download it also with bower.
This is the code:
<textarea id="editor-<?= $block_count ?>" name="block[<?= $block_count ?>][text][]" rows="10" cols="80" class="form-control"></textarea>
<script>
CKEDITOR.replace('editor-<?= $block_count ?>',{
customConfig: '../../dist/scripts/ckeditor.js',
skin: 'office2013'
});
</script>
But if it want to laod the skin i get this error message:
ckeditor.js:76 GET
htttp://myurl.com/src/bower_components/ckeditor/skins/office2013/editor.css?t=G87D
Can i define a skinpath to load it from teh bower path like:
CKEDITOR.replace('editor-<?= $block_count ?>',{
customConfig: '../../dist/scripts/ckeditor.js',
skinpath: 'src/bower_componnts/ckeditor-office2013-skin/office2013/',
skin: 'office2013'
});
Yes you can. Check the documentation. Quoting docs:
It is possible to install skins outside the default skin folder in the editor installation. In that case, the absolute URL path to that folder should be provided, separated by a comma ('skin_name,skin_path').
config.skin = 'moono';
config.skin = 'myskin,/customstuff/myskin/';
So, something similar should do the trick:
skin: 'office2013,/src/bower_components/ckeditor-office2013-skin/office2013/'

How can I check for Visual Studio updates via the command line?

In an attempt to streamline my Virtual Environment setup, I'm using Chocolatey to automate my VM.
Since I can run the cinst command to install Visual Studio
c:\> cinst VisualStudio2012Professional
I'm wondering if after it's installed, is there a command line switch to check for (and subsequently "install") updates within Visual Studio?
Something along the lines of...
"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe" /InstallUpdates
This should also extend to any extensions that are installed along side VS.
There is a way to check but it is not at all straight forward. Visual Studio Updates are published via an ATOM feed that is currently hosted here:
http://go.microsoft.com/fwlink/?LinkID=251032
This URL can be located in:
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Platform\Shell\Microsoft.VisualStudio.ExtensionManager.Implementation.pkgdef
Under the [$RootKey$\ExtensionManager\Repositories{52943709-1abb-4abe-b413-41e8bb6d0462}] key.
The above URL should not change for any version of Visual studio BUT that is not a guarantee. If you examine the response of http://go.microsoft.com/fwlink/?LinkID=290886, you will currently get this response:
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title type="text"></title>
<id>uuid:99B94631-1B1A-45A0-9C34-54F75988DD54;id=1</id>
<updated>2013-02-12T20:00:00-07:00</updated>
<entry>
<id>8EAF6C8E-1283-4EEE-AB6E-F0F087BFCBFF</id>
<title type="text">Visual Studio 2012 Update 3</title>
<summary type="text">Includes security updates, other critical updates, hotfixes, and feature packs that have been issued since the product was released.</summary>
<published>2012-12-01T21:00:00-07:00</published>
<updated>2012-12-01T21:00:00-07:00</updated>
<author>
<name>Microsoft Corp.</name>
</author>
<link rel="alternate" type="text/html" href="http://go.microsoft.com/fwlink/?LinkID=257044&clcid=0x409"/>
<link rel="releasenotes" type="text/html" href="http://go.microsoft.com/fwlink/?LinkID=257045&clcid=0x409"/>
<link rel="update" type="text" href="http://go.microsoft.com/fwlink/?LinkID=302339"/>
<!-- icon should be 32 x 32 pixels -->
<link rel="icon" type="text" href="http://visualstudiogallery.msdn.microsoft.com/Content/VisualStudio/VSDownload_32x.png"/>
<!-- preview image should be 200 x 200 pixels -->
<link rel="previewimage" type="text" href="http://visualstudiogallery.msdn.microsoft.com/Content/VisualStudio/VSDownload_200x.png"/>
<Vsix xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/developer/vsx-syndication-schema/2010">
<Id>8EAF6C8E-1283-4EEE-AB6E-F0F087BFCBFD</Id>
<Version>11.0.60610.01</Version>
<References />
</Vsix>
</entry>
<entry>
<id>28743233-1A36-4e67-8747-F072F8C76D1F</id>
<title type="text">Visual Studio Extensions for Windows Library for JavaScript</title>
<summary type="text">This release updates the development resources for the controls, CSS styles, and helper functions that are included in the Windows Library for JavaScript.</summary>
<published>2013-08-08T20:00:00-07:00</published>
<updated>2013-08-08T20:00:00-07:00</updated>
<author>
<name>Microsoft Corp.</name>
</author>
<link rel="alternate" type="text/html" href="http://go.microsoft.com/fwlink/?LinkId=260891&clcid=0x409"/>
<link rel="releasenotes" type="text/html" href="http://go.microsoft.com/fwlink/?LinkID=260892&clcid=0x409"/>
<link rel="update" type="text" href="http://go.microsoft.com/fwlink/?LinkID=260893"/>
<link rel="icon" type="text" href="http://visualstudiogallery.msdn.microsoft.com/Content/VisualStudio/VSDownload_32x.png"/>
<link rel="previewimage" type="text" href="http://visualstudiogallery.msdn.microsoft.com/Content/VisualStudio/VSDownload_200x.png"/>
<Vsix xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/developer/vsx-syndication-schema/2010">
<Id>Microsoft.WinJS</Id>
<Version>1.0.9200.20789</Version>
<References />
</Vsix>
</entry>
</feed>
Note that there are two entries in this feed and the one you are interested in is the one with a title beginning with "Visual Studio 2012 Update."
If the Version specified in this file (11.0.60610.01 here) is greater than the version you have on disk:
(Get-Item "${env:ProgramFiles(x86)}\Microsoft Visual Studio 11.0\common7\ide\devenv.exe").VersionInfo.ProductVersion
Then you would want to download and install the url in the Link/#Update node:
<link rel="update" type="text" href="http://go.microsoft.com/fwlink/?LinkID=302339"/>
That Url should redirect to an MSI that has the update.
Based on the information located in the Devenv Command Line Switches MSDN documentation. There is currently no way to call a command line swtich in order to check for / install updates to Visual Studio.
however Matt Wrock shows a nice workaround in his answer.
The answer from #Matt is outdated. For VS2019 follow this way:
Download file at https://aka.ms/vs/16/release/channel (it will be plain JSON file 'VisualStudio.16.Release.chman')
Check node: info->productDisplayVersion (or buildVersion) - they give enough info.

Cruise Control parsing "!" character in NAnt file

I have Cruise Control configured with a task to run a NAnt script, which runs an MSTest suite. MSTest allows me to specify test categories so I want to specify "!Integration" (which means "don't run Integration tests"). My Nant script successfully runs when I run it from the command line, but when Cruise runs it, the "!Integration" directive is being garbled -- the Cruise output suggests its inserting a line break after the '!' character. The result is that all my tests run, including integration tests.
Extract from ccnet.config:
<tasks>
<nant>
<executable>C:\nant\bin\nant.exe</executable>
<baseDirectory>C:\MyProject\BuildDirectory</baseDirectory>
<buildFile>MyProject.build</buildFile>
<targetList>
<target>CIServerBuild</target>
</targetList>
</nant>
</tasks>
Extract from MyProject.build:
<target name="CIServerBuild">
:
<call target="RunUnitTests" />
</target>
<target name="RunUnitTests">
<property name="TestCategories" value="!Integration" />
<call target="RunMSTest" failonerror="true"/>
</target>
<target name="RunMSTest">
<call target="BuildListOfTestContainers" failonerror="true"/>
<exec program="${MSTest.exe}"
commandline=" /category:"${TestCategories}" ${TestContainers} /resultsfile:${MSTest.ResultsFile} /nologo "
/>
</target>
Extract from Cruise output:
[exec] Starting 'C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe ( /category:"!
Integration" /testcontainer:C:\TaxWise\BuildDirectory\TaxWise\TaxWise.Data.Tests\bin\Debug\TaxWise.Data.Tests.dll /testcontainer:C:\TaxWise\BuildDirectory\TaxWise\TaxWise.Domain.Tests\bin\Debug\TaxWise.Domain.Tests.dll /testcontainer:C:\TaxWise\BuildDirectory\TaxWise\TaxWise.Infrastructure.Tests\bin\Debug\TaxWise.Infrastructure.Tests.dll /resultsfile:.\TestResults\UnitTests.trx /nologo )'
in 'C:\TaxWise\BuildDirectory'
I have tried replacing the '!' character with
'!'
but that made no difference.
Any ideas, anyone?
I suggest splitting the commandline attribute in the exec task into Nant arg elements.
http://nant.sourceforge.net/release/0.85/help/tasks/exec.html
You'll have more flexibility and the readability will increase.
Yes, perhaps it is not caused by CC. Try setting verbose="True" on the <exec> task and check the raw build protocol. Remember what you see on the report page is not the exact output (typically subject to line-wrap and coalescing whitespaces).
Maybe it depends on from where you run the script, a hidden dependency on a build property or different environment variables. You can check the latter using <exec program="cmd.exe" commandline="/c set" />. For the properties you can use the following script:
<script language="C#" prefix="util" verbose="true">
<code>
<![CDATA[
public static void ScriptMain(Project project)
{
foreach (DictionaryEntry entry in new System.Collections.SortedList(project.Properties) )
Console.WriteLine("{0}={1}", entry.Key, entry.Value);
}
]]>
</code>
</script>

Resources