Skip to content

Commit d7fb18c

Browse files
committed
added anchor links
1 parent 023e339 commit d7fb18c

17 files changed

+316
-46
lines changed

.rubocop.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# https://github.com/bbatsov/rubocop/blob/master/config/default.yml
2+
3+
Layout/AccessModifierIndentation:
4+
EnforcedStyle: indent
5+
AllCops:
6+
NewCops: enable
7+
8+
Layout/SpaceBeforeBrackets:
9+
Enabled: true
10+
Lint/AmbiguousAssignment:
11+
Enabled: true
12+
Lint/DuplicateBranch:
13+
Enabled: true
14+
Lint/DuplicateRegexpCharacterClassElement:
15+
Enabled: true
16+
Lint/EmptyBlock:
17+
Enabled: true
18+
Lint/EmptyClass:
19+
Enabled: true
20+
Lint/NoReturnInBeginEndBlocks:
21+
Enabled: true
22+
Lint/ToEnumArguments:
23+
Enabled: true
24+
Lint/UnexpectedBlockArity:
25+
Enabled: true
26+
Lint/UnmodifiedReduceAccumulator:
27+
Enabled: true
28+
Style/ArgumentsForwarding:
29+
Enabled: true
30+
Style/CollectionCompact:
31+
Enabled: true
32+
Style/DocumentDynamicEvalDefinition:
33+
Enabled: true
34+
Style/HashExcept:
35+
Enabled: true
36+
Style/NegatedIfElseCondition:
37+
Enabled: true
38+
Style/NilLambda:
39+
Enabled: true
40+
Style/RedundantArgument:
41+
Enabled: true
42+
Style/SwapValues:
43+
Enabled: true

_includes/comparisonMethods.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Comparison Method
1+
# [Comparison Method](#comparison_method)
22

33
It is possible to choose which method to use to compare two folders.
44
The method to use is strictly related to user needs, comparing source code (files large only few kilobytes) should use a content comparison but to find which movies (files larger than a gigabytes) are not present on right side is faster compare by file size or file timestamp.
@@ -44,4 +44,4 @@ The complete list of supported comparison methods
4444
</tr>
4545
</tbody>
4646
</table>
47-
</div>
47+
</div>

_includes/displayFiles.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Choose Files to View according to differences found
1+
# [Choose Files to View according to differences found](#choose_files_to_view_according_to_differences_found)
22

33
After the comparison complete you can choose which files to view
44
Definition: **Orphan** indicates a file present only on one side
@@ -38,13 +38,13 @@ The complete list of show options
3838
</table>
3939
</div>
4040

41-
## Choose Folders to View
41+
## [Choose Folders to View](#choose_folders_to_view)
4242

4343
It is possible to hide empty and orphans folders.
4444
Folders can be empty because they don't contains any file on disk or because all files/folders inside them are filtered.
4545
Orphans folders are present only on one side (left or right)
4646

47-
## Show Filtered Files
47+
## [Show Filtered Files](#show_filtered_files)
4848

4949
When a filter founds matches the elements are not visible but in case it's necessary to shown them you can click on the `Filtered` button.
5050
Default filters can be changed or totally deleted from `Session Preferences` window.

_includes/finderMetadata.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Compare Finder Metadata
1+
# [Compare Finder Metadata](#compare_finder_metadata)
22

33
It is possible to compare OSX Finder Metadata.
44
When the metadata comparison mismatches, for example left file's label is red and right file's label is blue, the other comparison methods (size, timestamp, content) are not evaluated.
@@ -24,4 +24,4 @@ The complete list of supported metadata
2424
</tr>
2525
</tbody>
2626
</table>
27-
</div>
27+
</div>

_includes/foldersTraversal.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Folders Traversal
1+
# [Folders Traversal](#folders_traversal)
22

33
User can choose to not traverse special files like symbolic links and packages
44

@@ -28,4 +28,4 @@ When this option is on if the file is a resource fork its size is determined fro
2828
</tr>
2929
</tbody>
3030
</table>
31-
</div>
31+
</div>

_includes/scripts.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
{% if site.minItemsToShowToc != null %}
1717
minItemsToShowToc: {{ site.minItemsToShowToc }},
1818
{% endif %}
19-
renderIn: '#toc-container'
19+
renderIn: '#toc-container',
20+
formatName: 'innerText',
21+
anchorPrefix: '',
2022
});
2123
});
2224
</script>

add_anchor.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const readline = require('readline');
2+
const fs = require('fs');
3+
4+
const readInterface = readline.createInterface({
5+
input: fs.createReadStream('unixshell.md'),
6+
// output: process.stdout,
7+
console: false
8+
});
9+
10+
let prevLine = null;
11+
12+
13+
readInterface.on('line', function(line) {
14+
if (line[0] === '=') {
15+
if (prevLine) {
16+
const anchor = prevLine.toLowerCase().replace(/[^a-z0-9]+/g, '_');
17+
console.log(`[${prevLine}](#${anchor})`);
18+
prevLine = null;
19+
}
20+
console.log(line);
21+
} else {
22+
if (prevLine !== null) {
23+
console.log(prevLine);
24+
}
25+
prevLine = line;
26+
}
27+
});
28+
readInterface.on('close', function(line) {
29+
if (prevLine) {
30+
console.log(prevLine);
31+
}
32+
});

add_anchor.sh

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/env bash
2+
# Add Markdown anchors to all Heading elements (only level 1 and level 2)
3+
# The "Heading Alternate Syntax" must have at least 4 = or - characters otherwise the anchor is not added
4+
5+
if [ $# -eq 0 ]
6+
then
7+
echo Missing file parameter
8+
exit 1
9+
fi
10+
11+
gawk '
12+
func toAnchor(str) {
13+
// is already link
14+
if (str ~ /^\s?\[/) {
15+
return str;
16+
}
17+
anchor = tolower(str);
18+
gsub(/[^a-z0-9]/, "_", anchor);
19+
gsub(/_+$/, "", anchor);
20+
21+
return "[" str "](#" anchor ")";
22+
}
23+
24+
func flush_buffer() {
25+
# --line_index;
26+
# line = lines[line_index];
27+
# delete lines[line_index];
28+
for (i = 0; i < line_index; i++) {
29+
print lines[i];
30+
}
31+
line_index = 0;
32+
}
33+
34+
func isHeaderAlreadySkipped(line) {
35+
if (header_read) {
36+
return 0;
37+
}
38+
print line;
39+
if (line == "---") {
40+
if (inside_header) {
41+
header_read=1;
42+
} else {
43+
inside_header = 1;
44+
}
45+
}
46+
return 1;
47+
}
48+
49+
BEGIN {
50+
header_read = 0;
51+
inside_header = 0;
52+
line_index = 0;
53+
}
54+
END {
55+
flush_buffer();
56+
}
57+
58+
/^(##?)/ {
59+
if (!inside_header) {
60+
flush_buffer();
61+
line=$0;
62+
gsub(/^#+/, "", line);
63+
print toAnchor(line);
64+
}
65+
}
66+
/^(====+)|(----+)/ {
67+
--line_index;
68+
last = lines[line_index];
69+
delete lines[line_index];
70+
flush_buffer();
71+
print toAnchor(last);
72+
}
73+
{
74+
if (!isHeaderAlreadySkipped($0)) {
75+
lines[line_index++] = $0;
76+
}
77+
}' \
78+
$1 >$1.bak
79+
mv $1.bak $1

add_anchors.rb

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/usr/bin/env ruby
2+
# Add Markdown anchors to Heading elements (only levels 1 and 2)
3+
# The "Heading Alternate Syntax" must have at least four '=' or '-' characters otherwise the anchor is not added
4+
# frozen_string_literal: true
5+
6+
require 'tempfile'
7+
require 'fileutils'
8+
9+
# rubocop:disable Metrics/MethodLength
10+
def read_header(source_file, dest_file)
11+
line = source_file.gets
12+
13+
return line unless line && line.chomp == '---'
14+
15+
found_header_start = false
16+
loop do
17+
line.chomp!
18+
dest_file.puts line
19+
if line == '---'
20+
return if found_header_start
21+
22+
found_header_start = true
23+
end
24+
break unless (line = source_file.gets)
25+
end
26+
end
27+
# rubocop:enable Metrics/MethodLength
28+
29+
def contain_link?(str)
30+
str =~ /\[.*?\]\(.*?\)/
31+
end
32+
33+
def to_anchor(str)
34+
return str if contain_link?(str)
35+
36+
anchor = str.downcase
37+
.gsub(/[^a-z0-9]+/, '_')
38+
.gsub(/_+$/, '')
39+
40+
"[#{str}](##{anchor})"
41+
end
42+
43+
def flush_buffer(buffer, dest_file)
44+
buffer.each { |l| dest_file.puts l }
45+
buffer.clear
46+
end
47+
48+
def heading_hash_syntax(line, buffer, dest_file)
49+
return false unless /^(====+)|(----+)/.match?(line)
50+
51+
last_line = buffer.pop
52+
flush_buffer(buffer, dest_file)
53+
dest_file.puts to_anchor(last_line)
54+
dest_file.puts line
55+
true
56+
end
57+
58+
def heading_alternate_syntax(line, buffer, dest_file)
59+
return false unless (m = line.match(/(^##?[^#])(.*)/))
60+
61+
flush_buffer(buffer, dest_file)
62+
dest_file.puts "#{m[1]}#{to_anchor(m[2])}"
63+
true
64+
end
65+
66+
def markdown_headings(line, buffer, dest_file)
67+
heading_hash_syntax(line, buffer, dest_file) || heading_alternate_syntax(line, buffer, dest_file)
68+
end
69+
70+
def process_file(source_file, dest_file)
71+
buffer = []
72+
73+
line = read_header(source_file, dest_file)
74+
# check the first line after the header is a markdown heading
75+
markdown_headings(line.chomp, buffer, dest_file) if line
76+
77+
while (line = source_file.gets)
78+
line.chomp!
79+
80+
buffer << line unless markdown_headings(line, buffer, dest_file)
81+
end
82+
83+
flush_buffer(buffer, dest_file)
84+
end
85+
86+
if ARGV.empty?
87+
puts 'Specify file'
88+
exit 1
89+
end
90+
91+
file = File.open(ARGV[0], 'r')
92+
temp_file = Tempfile.new('anchors')
93+
94+
process_file(file, temp_file)
95+
96+
file.close
97+
temp_file.close
98+
99+
FileUtils.cp(temp_file.path, ARGV[0])
100+
temp_file.unlink

alignRules.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ subtitle: Change the default file names alignment method
1010

1111
Before being compared two files they must be aligned, the alignment rule can be configured
1212

13-
# Align by Name Case Sensitivity
13+
# [Align by Name Case Sensitivity](#align_by_name_case_sensitivity)
1414

1515
The default alignment method compares file name strings, if they are match case then they will be aligned.
1616
Suppose you have the scenario shown below
@@ -65,7 +65,7 @@ This can be achieved selecting 'Ignore File Name Case' from popup menu.</p>
6565
</table>
6666
</div>
6767

68-
# Align by HFS+ Filesystem Case
68+
# [Align by HFS+ Filesystem Case](#align_by_hfs_filesystem_case)
6969

7070
Normally the <acronym title="Hierarchical File System">HFS+</acronym> disks are formatted ignoring the file name case, so if we have winter.jpg and WINTER.JPG they cannot be created on same directory (because they have the same name).
7171

@@ -79,7 +79,7 @@ It is possible to let VisualDiffer determine the file name alignment case algori
7979

8080
If the last scenario is true, the alignment will try to be smart, first it searches if a match case is available (winter.jpg with winter.jpg) then it tries to align with the most similar name.
8181

82-
# Align by User Defined Rules (required OSX Lion or above)
82+
# [Align by User Defined Rules (required OSX Lion or above)](#align_by_user_defined_rules_required_osx_lion_or_above)
8383

8484
There are scenarios where it is necessary to align files having different names.
8585
The most simple scenario has files with same name but different extension as shown below
@@ -138,15 +138,15 @@ Suppose you want to align ignoring the file extension to produce the result show
138138

139139
This can be achieved using VisualDiffer 'user defined alignment rules'.
140140

141-
## Managing Alignment Rules
141+
## [Managing Alignment Rules](#managing_alignment_rules)
142142

143143
You can create, edit or delete rules from Session Preferences Dialog
144144

145145
![image]({{ site.prefixDir }}img/ternaryop/vd/screenshots/wiki/sessionPrefAlignment.png)
146146

147147
More rules can be assigned to a VisualDiffer session comparison, they are evaluated from top to bottom.
148148

149-
## Creating a Rule
149+
## [Creating a Rule](#creating_a_rule)
150150

151151
When you add a new rule (or edit an existing one) you access to the dialog shown below
152152

@@ -159,11 +159,11 @@ A rule has
159159

160160
_If you are not familiar with regular expressions please refer to [ICU](http://userguide.icu-project.org/strings/regexp) documentation._
161161

162-
## Left Regular Expression
162+
## [Left Regular Expression](#left_regular_expression)
163163

164164
The left regexp is used to match a filename on the left side of VisualDiffer Folder View, we want to find all jpg files so we create a group `(.*)` followed by `.jpg` extension.
165165

166-
## Right Pattern Expression
166+
## [Right Pattern Expression](#right_pattern_expression)
167167

168168
Notice the right expression **isn't** a regular expression, it should contain some special patterns used to access to regular expression groups (if any).
169169

@@ -201,6 +201,6 @@ But `002.jpg` and `002.RAW` files are not aligned because `002.RAW` extension is
201201

202202
![image]({{ site.prefixDir }}img/ternaryop/vd/screenshots/wiki/alignRuleIgnoreCase.png)
203203

204-
## Test Rule
204+
## [Test Rule](#test_rule)
205205

206-
It is possible to verify immediately if the expressions work as expected using the 'Test Rule', just type a file name and the 'Result' field will be filled accordingly.
206+
It is possible to verify immediately if the expressions work as expected using the 'Test Rule', just type a file name and the 'Result' field will be filled accordingly.

0 commit comments

Comments
 (0)