Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
magicseteditor
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
magicseteditor
Commits
a15c744d
Commit
a15c744d
authored
Jul 13, 2007
by
twanvl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Some tweaks to the syntax highlighting and document formating
parent
d1574f12
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
45 deletions
+55
-45
tools/website/drupal/mse-drupal-modules/autoformat.inc
tools/website/drupal/mse-drupal-modules/autoformat.inc
+52
-42
tools/website/drupal/mse-drupal-modules/highlight.inc
tools/website/drupal/mse-drupal-modules/highlight.inc
+3
-3
No files found.
tools/website/drupal/mse-drupal-modules/autoformat.inc
View file @
a15c744d
...
...
@@ -8,6 +8,7 @@ require_once('./modules/mse-drupal-modules/highlight.inc');
global
$nice_names
;
$nice_names
=
array
(
'type:double'
=>
'real number'
,
'type:int'
=>
'number'
,
'type:indexmap'
=>
'map'
,
);
...
...
@@ -17,21 +18,21 @@ $nice_names = array(
* Format $text, recognizes commands at the start of each line
*/
function
autoformat
(
$text
,
$first
=
true
)
{
global
$autoformat_lines
;
global
$autoformat_
_
lines
;
// Lines in the input
$autoformat_lines
=
is_array
(
$text
)
?
$text
:
explode
(
"
\n
"
,
$text
);
$autoformat_
_
lines
=
is_array
(
$text
)
?
$text
:
explode
(
"
\n
"
,
$text
);
// Result text
$i
=
0
;
return
autoformat_handle
(
$i
,
''
,
$first
);
return
autoformat_
_
handle
(
$i
,
''
,
$first
);
}
function
autoformat_handle
(
&
$i
,
$prefix
,
$first
,
$fail_same
=
false
)
{
global
$autoformat_lines
;
function
autoformat_
_
handle
(
&
$i
,
$prefix
,
$first
,
$fail_same
=
false
)
{
global
$autoformat_
_
lines
;
$text
=
''
;
$state
=
''
;
// While not at the end...
while
(
$i
<
count
(
$autoformat_lines
))
{
$line
=
$autoformat_lines
[
$i
++
];
while
(
$i
<
count
(
$autoformat_
_
lines
))
{
$line
=
$autoformat_
_
lines
[
$i
++
];
$len
=
min
(
strlen
(
$line
),
strlen
(
$prefix
));
...
...
@@ -39,7 +40,7 @@ function autoformat_handle(&$i, $prefix, $first, $fail_same = false) {
for
(
$j
=
0
;
$j
<
$len
;
++
$j
)
{
if
(
$prefix
{
$j
}
!=
$line
{
$j
}
&&
$line
{
$j
}
!=
' '
)
{
$i
--
;
if
(
$state
==
'|'
)
$text
.=
autoformat_table
(
$table
);
if
(
$state
==
'|'
)
$text
.=
autoformat_
_
table
(
$table
);
return
$text
;
}
}
...
...
@@ -55,11 +56,11 @@ function autoformat_handle(&$i, $prefix, $first, $fail_same = false) {
// Determine line type
if
(
strlen
(
$oldline
)
<
strlen
(
$prefix
))
{
// empty line => break out of this level
if
(
$state
==
'|'
)
$text
.=
autoformat_table
(
$table
);
if
(
$state
==
'|'
)
$text
.=
autoformat_
_
table
(
$table
);
return
$text
;
}
else
if
(
$line
==
''
)
{
// empty line => paragraph separator
if
(
$state
==
'|'
)
$text
.=
autoformat_table
(
$table
);
if
(
$state
==
'|'
)
$text
.=
autoformat_
_
table
(
$table
);
$state
=
''
;
$text
.=
"
\n
"
;
...
...
@@ -76,20 +77,20 @@ function autoformat_handle(&$i, $prefix, $first, $fail_same = false) {
$table
[
count
(
$table
)
-
1
][
'lines'
][]
=
$line
;
}
else
{
if
(
$state
==
'|'
)
$text
.=
autoformat_table
(
$table
);
if
(
$state
==
'|'
)
$text
.=
autoformat_
_
table
(
$table
);
// Headings
if
(
$prefix
==
''
&&
preg_match
(
'@^====.*====$@'
,
$line
))
{
// level 4 heading
$text
.=
'<h4>'
.
autoformat_line
(
substr
(
$line
,
4
,
-
4
))
.
"</h4>
\n
"
;
$text
.=
'<h4>'
.
autoformat_
_
line
(
substr
(
$line
,
4
,
-
4
))
.
"</h4>
\n
"
;
$state
=
''
;
}
elseif
(
$prefix
==
''
&&
preg_match
(
'@^===.*===$@'
,
$line
))
{
// level 3 heading
$text
.=
'<h3>'
.
autoformat_line
(
substr
(
$line
,
3
,
-
3
))
.
"</h3>
\n
"
;
$text
.=
'<h3>'
.
autoformat_
_
line
(
substr
(
$line
,
3
,
-
3
))
.
"</h3>
\n
"
;
$state
=
''
;
}
elseif
(
$prefix
==
''
&&
(
preg_match
(
'@^==.*==$@'
,
$line
)
||
preg_match
(
'@^--.*--$@'
,
$line
)))
{
// level 2 heading
$text
.=
'<h2>'
.
autoformat_line
(
substr
(
$line
,
2
,
-
2
))
.
"</h2>
\n
"
;
$text
.=
'<h2>'
.
autoformat_
_
line
(
substr
(
$line
,
2
,
-
2
))
.
"</h2>
\n
"
;
$state
=
''
;
// Lists
...
...
@@ -97,14 +98,14 @@ function autoformat_handle(&$i, $prefix, $first, $fail_same = false) {
if
(
$state
==
'*'
)
$text
=
substr
(
$text
,
0
,
-
5
);
else
$text
.=
'<ul>'
;
$i
--
;
$text
.=
'<li>'
.
autoformat_handle
(
$i
,
$current_prefix
.
'*'
,
false
,
true
)
.
"</li>
\n
"
;
$text
.=
'<li>'
.
autoformat_
_
handle
(
$i
,
$current_prefix
.
'*'
,
false
,
true
)
.
"</li>
\n
"
;
$text
.=
'</ul>'
;
$state
=
'*'
;
}
elseif
(
$line
{
0
}
==
'#'
)
{
if
(
$state
==
'#'
)
$text
=
substr
(
$text
,
0
,
-
5
);
else
$text
.=
'<ol>'
;
$i
--
;
$text
.=
'<li>'
.
autoformat_handle
(
$i
,
$current_prefix
.
'#'
,
false
,
true
)
.
"</li>
\n
"
;
$text
.=
'<li>'
.
autoformat_
_
handle
(
$i
,
$current_prefix
.
'#'
,
false
,
true
)
.
"</li>
\n
"
;
$text
.=
'</ol>'
;
$state
=
'#'
;
}
elseif
(
$line
{
0
}
==
':'
)
{
...
...
@@ -112,7 +113,7 @@ function autoformat_handle(&$i, $prefix, $first, $fail_same = false) {
elseif
(
$state
==
';'
)
$text
=
substr
(
$text
,
0
,
-
5
)
.
'<dt>'
;
else
$text
.=
'<dl><dt>'
;
$i
--
;
$text
.=
"
\n
"
.
autoformat_handle
(
$i
,
$current_prefix
.
':'
,
false
);
$text
.=
"
\n
"
.
autoformat_
_
handle
(
$i
,
$current_prefix
.
':'
,
false
);
$text
.=
'</dt></dl>'
;
$state
=
':'
;
}
elseif
(
$line
{
0
}
==
';'
)
{
...
...
@@ -120,7 +121,7 @@ function autoformat_handle(&$i, $prefix, $first, $fail_same = false) {
elseif
(
$state
==
':'
)
$text
=
substr
(
$text
,
0
,
-
5
)
.
'<dd>'
;
else
$text
.=
'<dl><dd>'
;
$i
--
;
$text
.=
"
\n
"
.
autoformat_handle
(
$i
,
$current_prefix
.
';'
,
false
);
$text
.=
"
\n
"
.
autoformat_
_
handle
(
$i
,
$current_prefix
.
';'
,
false
);
$text
.=
'</dd></dl>'
;
$state
=
';'
;
}
elseif
(
$line
{
0
}
==
'>'
)
{
...
...
@@ -139,7 +140,7 @@ function autoformat_handle(&$i, $prefix, $first, $fail_same = false) {
$state
=
']'
;
// Just text
}
else
if
(
$fail_same
&&
$autoformat_lines
[
$i
-
1
]{
$len
-
1
}
!=
' '
&&
$text
!=
''
)
{
}
else
if
(
$fail_same
&&
$autoformat_
_
lines
[
$i
-
1
]{
$len
-
1
}
!=
' '
&&
$text
!=
''
)
{
// consecutive * and # lines are different items
$i
--
;
return
$text
;
...
...
@@ -149,7 +150,7 @@ function autoformat_handle(&$i, $prefix, $first, $fail_same = false) {
if
(
$state
==
'P'
)
$text
=
substr
(
$text
,
0
,
-
4
);
else
$text
.=
'<p>'
;
}
$text
.=
autoformat_line
(
$line
)
.
"
\n
"
;
$text
.=
autoformat_
_
line
(
$line
)
.
"
\n
"
;
if
(
$first
)
{
$text
.=
'</p>'
;
}
...
...
@@ -159,14 +160,14 @@ function autoformat_handle(&$i, $prefix, $first, $fail_same = false) {
}
//print_r("\n\n==================[$prefix]=================\n$text");
//print_r("\n==================///=================\n");
if
(
$state
==
'|'
)
$text
.=
autoformat_table
(
$table
);
if
(
$state
==
'|'
)
$text
.=
autoformat_
_
table
(
$table
);
return
$text
;
}
/**
* Format a table, given the rows
*/
function
autoformat_table
(
$rows
)
{
function
autoformat_
_
table
(
$rows
)
{
foreach
(
$rows
as
$k
=>
$r
)
{
// split lines into columns
$cols
=
array
();
...
...
@@ -207,8 +208,8 @@ function autoformat_table($rows) {
}
}
global
$autoformat_lines
;
$l
=
$autoformat_lines
;
global
$autoformat_
_
lines
;
$l
=
$autoformat_
_
lines
;
$text
=
'<table>'
;
foreach
(
$newrows
as
$k
=>
$r
)
{
$text
.=
$k
%
2
==
0
?
'<tr class="even">'
:
'<tr class="odd">'
;
...
...
@@ -226,7 +227,7 @@ function autoformat_table($rows) {
$text
.=
'</tr>'
;
}
$text
.=
'</table>'
;
$autoformat_lines
=
$l
;
$autoformat_
_
lines
=
$l
;
return
$text
;
}
...
...
@@ -234,42 +235,51 @@ function autoformat_table($rows) {
/**
* Expand formting tags inside a single line,
*/
function
autoformat_line
(
$line
)
{
function
autoformat_
_
line
(
$line
)
{
$line
=
preg_replace
(
"/'''(.*?)'''/"
,
"<strong>
\\
1</strong>"
,
$line
);
$line
=
preg_replace
(
"/''(.*?)''/"
,
"<em>
\\
1</em>"
,
$line
);
$line
=
preg_replace_callback
(
"/@(.*?)@/"
,
"autoformat_code"
,
$line
);
$line
=
preg_replace_callback
(
"/\[\[(.*?)\|(.*?)]]
(s?)/"
,
"autoformat
_link_s"
,
$line
);
$line
=
preg_replace_callback
(
"/\[\[(.*?)]](s?)/"
,
"autoformat_link"
,
$line
);
$line
=
preg_replace_callback
(
"/@(.*?)@/"
,
"autoformat_
_
code"
,
$line
);
$line
=
preg_replace_callback
(
"/\[\[(.*?)\|(.*?)]]
/"
,
"autoformat_
_link_s"
,
$line
);
$line
=
preg_replace_callback
(
"/\[\[(.*?)]](s?)/"
,
"autoformat_
_
link"
,
$line
);
return
$line
;
}
function
autoformat_code
(
$matches
)
{
function
autoformat_
_
code
(
$matches
)
{
return
'<tt>'
.
syntax_highlight
(
htmlspecialchars
(
$matches
[
1
]))
.
'</tt>'
;
}
function
autoformat_link
(
$matches
)
{
return
'<a href="'
.
autoformat_
url
(
$matches
[
1
])
.
'">'
.
autoformat_title
(
$matches
[
1
])
.
$matches
[
2
]
.
'</a>'
;
function
autoformat_
_
link
(
$matches
)
{
return
'<a href="'
.
autoformat_
_url
(
$matches
[
1
])
.
'">'
.
autoformat__title
(
$matches
[
1
],
$matches
[
2
])
.
'</a>'
;
}
function
autoformat_link_s
(
$matches
)
{
return
'<a href="'
.
autoformat_
url
(
$matches
[
1
])
.
'">'
.
$matches
[
2
]
.
$matches
[
3
]
.
'</a>'
;
function
autoformat_
_
link_s
(
$matches
)
{
return
'<a href="'
.
autoformat_
_url
(
$matches
[
1
])
.
'">'
.
$matches
[
2
]
.
'</a>'
;
}
function
autoformat_url
(
$url
)
{
if
(
preg_match
(
"/^type:/"
,
$url
))
{
return
url
(
"doc/type/"
.
substr
(
$url
,
5
));
}
elseif
(
preg_match
(
"/^fun:/"
,
$url
))
{
return
url
(
"doc/function/"
.
substr
(
$url
,
4
));
function
autoformat__url
(
$url
)
{
if
(
preg_match
(
"/^(type|fun|script|file):(.*)/i"
,
$url
,
$matches
))
{
$part
=
$matches
[
1
];
if
(
$part
==
'fun'
)
$part
=
'function'
;
$sub
=
str_replace
(
' '
,
'_'
,
strtolower
(
$matches
[
2
]));
return
url
(
'doc/'
.
$part
.
'/'
.
$sub
);
}
else
{
return
url
(
$url
);
}
}
function
autoformat_
title
(
$url
)
{
function
autoformat_
_title
(
$url
,
$s
=
''
)
{
global
$nice_names
;
if
(
isset
(
$nice_names
[
$url
]))
{
return
$nice_names
[
$url
];
$url
=
$nice_names
[
$url
];
}
else
if
(
preg_match
(
"/.*:$/"
,
$url
))
{
$url
=
preg_replace
(
"/:/"
,
""
,
$url
);
}
else
if
(
!
preg_match
(
"@^http://@"
,
$url
))
{
$url
=
preg_replace
(
"/.*:/"
,
""
,
$url
);
}
if
(
$s
==
's'
&&
$url
{
strlen
(
$url
)
-
1
}
==
'y'
)
{
$url
=
substr
(
$url
,
0
,
-
1
)
.
'ies'
;
}
else
{
return
preg_replace
(
"/.*:/"
,
""
,
$url
)
;
$url
.=
$s
;
}
return
$url
;
}
?>
\ No newline at end of file
tools/website/drupal/mse-drupal-modules/highlight.inc
View file @
a15c744d
...
...
@@ -3,7 +3,7 @@
// Syntax highlighting of script and reader code
function
syntax_highlight
(
$code
)
{
if
(
preg_match
(
"@^(\s*#.*
\n
)*\s*[
a-zA-Z0-9 _/,]+:[^=]
@"
,
$code
))
{
if
(
preg_match
(
"@^(\s*#.*
\n
)*\s*[
-a-zA-Z0-9 _/,]+:([^=]|$)
@"
,
$code
))
{
return
highlight_reader
(
$code
);
}
else
{
return
highlight_script
(
$code
);
...
...
@@ -55,11 +55,11 @@ function highlight_reader($code) {
function
highlight_script
(
$code
)
{
$ret
=
''
;
while
(
strlen
(
$code
))
{
if
(
preg_match
(
"@^(if|then|else|for|in|do|and|or|not|rgb)\b@"
,
$code
,
$matches
))
{
if
(
preg_match
(
"@^(if|then|else|for|in|do|and|or|
xor|
not|rgb)\b@"
,
$code
,
$matches
))
{
$ret
.=
"<span class='hl-kw'>"
.
$matches
[
0
]
.
"</span>"
;
}
else
if
(
preg_match
(
"@^(include file:)(.*)@"
,
$code
,
$matches
))
{
$ret
.=
"<span class='hl-key'>"
.
$matches
[
1
]
.
"</span>"
.
$matches
[
2
];
}
else
if
(
preg_match
(
"@^
[0-9][0-9.]*
@"
,
$code
,
$matches
))
{
}
else
if
(
preg_match
(
"@^
([0-9][0-9.]*|true|false)
@"
,
$code
,
$matches
))
{
$ret
.=
"<span class='hl-num'>"
.
$matches
[
0
]
.
"</span>"
;
}
else
if
(
preg_match
(
"@^(
\"
|")(
\\\\
.|[^
\\\\
])*?(
\"
|")@"
,
$code
,
$matches
))
{
$ret
.=
"<span class='hl-str'>"
.
$matches
[
0
]
.
"</span>"
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment