-
Notifications
You must be signed in to change notification settings - Fork 13
/
h5.tmCommand
73 lines (70 loc) · 2.14 KB
/
h5.tmCommand
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>beforeRunningCommand</key>
<string>nop</string>
<key>command</key>
<string>#!/usr/bin/env php
<?php
// Turn a line or selection into a heading
// Created: 23.12.08 Author: timothy.c.bates@gmail.com
// nb: Overrides existing cmd-n
// Also Works on multiple lines and lines that already have a heading applied
$level = '=';
$thisNum = 5;
$newLevel = str_repeat ( $level, $thisNum); // Change this to alter the level being affected
$o = array();
if (0) { //set to 1 for debugging
echo "<pre>";
$existing = "$level$level$level Why is is this so badly formed? $level$level$level";
$existing = "$level$level$level Why is is this so badly formed? $level$level$level
$level$level$level Why is is this so badly formed? $level$level$level
$level$level$level Why is is this so badly formed? $level$level$level";
// $existing = ""; // test case of empty line
echo "started with:\n<font color=red>\"$existing\"</font>\n-->\n";
} else {
$existing = fread(STDIN, 1024);
}
$aLines = explode("\n", $existing);
$l = count($aLines);
foreach ($aLines as $key => $line) {
$line = trim ( $line);
if (empty($line)) {
if ($l>1) {
$o[] = "";
}else{
$o[] = "$newLevel \${1:Level $thisNum heading} $newLevel";
}
} else {
$new = trim ( $line, " $level" ); //trim existing markers from either end
$o[] = "$newLevel $new $newLevel";
}
}
echo implode("\n", $o);
?>
</string>
<key>fallbackInput</key>
<string>line</string>
<key>input</key>
<string>selection</string>
<key>inputFormat</key>
<string>text</string>
<key>keyEquivalent</key>
<string>@5</string>
<key>name</key>
<string>h5</string>
<key>outputCaret</key>
<string>afterOutput</string>
<key>outputFormat</key>
<string>snippet</string>
<key>outputLocation</key>
<string>replaceInput</string>
<key>scope</key>
<string>text.html.mediawiki</string>
<key>uuid</key>
<string>0FBF756C-651C-4AFC-92A2-9E229F5E3775</string>
<key>version</key>
<integer>2</integer>
</dict>
</plist>