In response to Xx Dark Wizard xX
Someone was helping me do this on aim, but he had to go somewere and i am stuck with
client
var/list/showcodes[0]
Topic(href, href_list[], hsrc)
if("showcode" in href_list)
var/client/owner = hsrc
if(!owner) return
var/code = text2num(href_list["code_id"])
if(code > owner.showcodes.len) return
code = owner.showcodes[code]
output_showcode(code)
verb/showcode(code as message)
showcodes.Add(code)
world << "[name]'s <a href=\"?showcode&src=\ref[src]&code_id=[showcodes.len]\">showcode</a>"
proc/output_showcode(code)
var/html = {"
<html>
<head><title>Showcode</title></head>
<body>
[code_highlight(code)]</body>
</html>"}

src << browse(html, "window=showcode"
proc/code_highlight(code)
//right here is where you would do your code highlighting


now how do i make the usr shows linktocode








here is all of the library

//Insert insertion into text
//Sticks insertion on the end of text by default
proc/_insert_text(text,insertion,insertion_point = length(text) + 1)
return copytext(text,1,insertion_point) + insertion + copytext(text,insertion_point)


var/list/dm_keywords = list("var","tmp","in","goto","global","static","return","del","do","if","else","continue",\
"const","while","break","switch","new","as","for","set","verb","proc","arg")

proc/get_dm_keywords(text)
var/list/result = list()
for(var/keyword in dm_keywords)
var/keyword_pos=findText(text, keyword)
while(keyword_pos)
if((keyword_pos < 2 || !isletter_or_underscore(copytext(text,keyword_pos-1,keyword_pos))) && (length(text) < keyword_pos+length(keyword) || !isletter_or_underscore(copytext(text,keyword_pos+length(keyword),keyword_pos+length(keyword)+1))))
result["[keyword_pos]"] = keyword
keyword_pos=findText(text, keyword, keyword_pos+1)
return result

proc/isletter_or_underscore(char)
var/ascii_char = text2ascii(char)
if(ascii_char >= 97 && ascii_char <= 122) return TRUE //lower
if(ascii_char >= 65 && ascii_char <= 90) return TRUE //upper
if(char == "_") return TRUE


proc/_dmsh_string_replace(string,find,replace)
var/pos = findtext(string,find)
while(pos)
string = copytext(string,1,pos) + replace + copytext(string,pos+length(find))
pos = findtext(string,find,pos)
return string

var/list/html_entities = list("&#34;" = "\"","&#39;" = "\'")

client/New()
.=..()
src << browse_rsc('dm_syntax.css')

proc/syntax_highlight(code,full_doc = 0,title = "DM Code")
ASSERT(istext(code))
//censor HTML
code = html_encode(code)
for(var/entity in html_entities)
code = _dmsh_string_replace(code,entity,html_entities["[entity]"])
var/in_singstring = 0
var/in_doubstring = 0
var/in_bigstring = 0
var/in_brackets = 0
var/in_singcomment = 0
var/in_multicomment = 0
var/in_preprocess = 0
//Don't highlight quotes around HTML attributes
var/in_tag = 0
//Detect if any changes have been made during last loop iteration
var/change_made = 0
var/last_change_made = 0
var/list/found_keywords
var/pos = 0
while(1)
pos++
last_change_made = change_made
change_made = 0
//The text character currently being looked at
var/char = text2ascii(code,pos)
//if unescaped newline is starting
if(char == 10 && pos > 2 && copytext(code,pos - 2,pos - 1) != 92)
if(in_preprocess)
code = _insert_text(code,"</span>",pos + 1)
in_preprocess = 0
pos += length("</span>")
change_made = 1
if(in_singcomment)
code = _insert_text(code,"</span>",pos + 1)
in_singcomment = 0
pos += length("</span>")
change_made = 1
//if multicomment is ending
if(char == 47 && pos > 1 && text2ascii(code,pos - 1) == 42)
code = _insert_text(code,"</span>",pos + 1)
in_multicomment = 0
pos += length("</span>")
change_made = 1
//if we aren't inside a comment and the char isn't escaped
if(!in_singcomment && !in_multicomment)
//escaped text
if(pos > 1 && text2ascii(code,pos - 1) == 92 && (in_doubstring || in_bigstring))
//account for an escaped backslash
if(pos > 2)
if(!(text2ascii(code,pos - 1) == 92 && text2ascii(code,pos - 2) == 92)) continue
else continue
//singstring
if(char == 39 && !in_doubstring && !in_tag)
if(in_singstring && !in_brackets && !in_bigstring)
code = _insert_text(code,"</span>",pos + 1)
in_singstring = 0
pos += length("</span>")
change_made = 1
else
code = _insert_text(code,"<span class=\"dmstring\">",pos)
in_singstring = 1
pos += length("<span class=\"dmstring\">")
change_made = 1
//doubstring start + end and bigstring start
if(char == 34)
//doubstring end
if(in_doubstring && !in_brackets && !in_bigstring && !in_tag)
code = _insert_text(code,"</span>",pos + 1)
in_doubstring = 0
pos += length("</span>") + 1
change_made = 1
else
//bigstring start
if(pos > 1 && text2ascii(code,pos - 1) == 123 && !in_bigstring)
code = _insert_text(code,"<span class=\"dmstring\">",pos - 1)
in_bigstring = 1
pos += length("<span class=\"dmstring\">") + 1
change_made = 1
//doubstring start
else if(!in_doubstring && !in_bigstring && !in_singstring && !in_tag)
code = _insert_text(code,"<span class=\"dmstring\">",pos)
in_doubstring = 1
pos += length("<span class=\"dmstring\">")
change_made = 1
//bigstring end
if(char == 125 && in_bigstring && text2ascii(code,pos - 1) == 34)
code = _insert_text(code,"</span>",pos + 1)
in_bigstring = 0
pos += length("</span>") + 1
change_made = 1
if(!in_doubstring && !in_singstring && !in_bigstring)
//Check for comment starts
if(pos > 1 && text2ascii(code,pos - 1) == 47)
if(char == 47)
//singcomment after preprocessor -- on same line
if(in_preprocess)
code = _insert_text(code,"</span>",pos - 1)
in_preprocess = 0
pos += length("</span>")
code = _insert_text(code,"<span class=\"dmcomment\">",pos - 1)
in_singcomment = 1
pos += length("<span class=\"dmcomment\">")
change_made = 1
if(char == 42)
code = _insert_text(code,"<span class=\"dmcomment\">",pos - 1)
in_multicomment = 1
pos += length("<span class=\"dmcomment\">") + 1//@SPECIAL
change_made = 1
//preprocessor
if(char == 35)
code = _insert_text(code,"<span class=\"dmpreprocessor\">",pos)
in_preprocess = 1
pos += length("<span class=\"dmpreprocessor\">")
change_made = 1
//keywords
if(last_change_made || pos == 1) found_keywords = get_dm_keywords(code)
if((num2text(pos) in found_keywords) && !in_preprocess)
code = _insert_text(code,"<span class=\"dmkeyword\">",pos)
pos += length("<span class=\"dmkeyword\">") + length(found_keywords["[pos]"])
code = _insert_text(code,"</span>",pos)//@SPECIAL
pos += length("</span>") - 1
change_made = 1
if(in_doubstring)
//in_tag
if(char == 60) in_tag = 1
if(char == 62 && in_tag) in_tag = 0
if(in_doubstring || in_bigstring)
//bracket start
if(char == 91)
in_brackets++
if(in_brackets == 1)
//end string
code = _insert_text(code,"</span>",pos)
pos += length("</span>")
//start brackets
code = _insert_text(code,"<span class=\"dmbrace\">",pos)
pos += length("<span class=\"dmbrace\">")
change_made = 1
//bracket end
if(char == 93 && in_brackets)
in_brackets--
if(!in_brackets)
code = _insert_text(code,"</span>",pos + 1)
pos += length("</span>") + 1
//continue on with string
code = _insert_text(code,"<span class=\"dmstring\">",pos)
pos += length("<span class=\"dmstring\">")
//hacky doubstring stop
if(in_doubstring && text2ascii(code,pos) == 34)
code = _insert_text(code,"</span>",pos + 1)
in_doubstring = 0
pos += length("</span>") + 1
change_made = 1
//Break out of the loop here
if(pos >= length(code) || char == 0)
if(!full_doc) return "<pre class=\"dmcode\">[code]</pre>"
else return {"
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<link rel="stylesheet" type="text/css" href="dm_syntax.css" />
<title>
[title]</title>
</head>
<body>
<pre class=\"dmcode\">
[code]</pre>
</body>
</html>
"}



//and here is a demo for it





client/verb
Test_Syntax_Highlighting(code as message)
set name = "Test Syntax Highlighting (full_doc)"
//Put the code in the browser as a full document
src << browse(syntax_highlight(code,1))

Test_Syntax_Highlighting_Without_Fulldoc(code as message)
set name = "Test Syntax Highlighting (no full_doc)"
//Note that here, syntax_highlight() is called with
//full_doc equal to 0. If full_doc is equal to 0,
//syntax_highlight() is meant to be embedded into
//a string.
src << browse({"
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="dm_syntax.css" />
<title>DM Code</title>
</head>
<body bgcolor=\"#110099\">
<table bgcolor="#ffffff" width="100%" border="1" cellpadding="5">
<tr>
<td>
[syntax_highlight(code)]
</td>
</tr>
</table>
</body>
</html>
"}
)
May I suggest using a different library? I find Lummox's DM sytnax highlighter not only to be faster, but I've never seen it fail to highlight the syntax like Wizkidd0123's does. Of course, you can't really blame Wizkidd, he doesn't have much time to fix all that stuff.
In response to CaptFalcon33035
damn, all that for nothing

How do i make a verb that will show the verb in a link my code. Or can you add the few lines of code for thr other one.
In response to Xx Dark Wizard xX
Nobody will make anything for you, you have to learn how to MAKE things for yourself, not CHANGE them (though really, you could've changed a few stuff and made it work anyways).

Here's my final post (well, maybe not) on Topic():

To load graphics in the browse(), you need to use browse_rsc()

browse() works like this: browse({"HTML Code Here like <a href=byond://?Apple /> <-- Yes I know that is wrongish"}, "browse() optional options here")

I already gave you a lot of information on how to use browse() and how to make it into a popup [though I admit I didn't talked indept about Topic()... but that's what DM Reference is there for)

If you can't get it to work, leave it alone and come back to it later... if you still can't get it working... give up on it >_<

Do not ask others to do something specific for you, you help vampire!

...this is the reason why I shouldn't be a teacher, I lack the patience ;0

- GhostAnime
In response to CaptFalcon33035
CaptFalcon33035 wrote:
I've never seen it fail to highlight the syntax like Wizkidd0123's does.

(It's fixed now =P)
Xx Dark Wizard xX wrote:
Does anyone know how to make it show whoever shows "code" link.

See [link] for one method (well, the highlighter isn't incorporated there, of course, but it -is- a method of making a showcode verb, which may be what you need help with. You might also want to see the browse() ref entry, which will explain to you how to make popup windows with browse using its second argument).
In response to Wizkidd0123
w00t! *goes to test*

I admire your work, to all of you who have made syntax highlighters and plan to in DM. I'd not have the patience to sit and do it.

[Edit]

I think I might've found another bug, though it looks to be the same one I found last time. I don't know how to explain it, so try higlighting Lummox's Syntax Highlighter. It messes up on the text quotes around static (which has turned blue by the way), and the comma before "static", which has also turned blue, maybe by text macro.
In response to CaptFalcon33035
I have the message in xooxer's post, but how does that apply to the library?
In response to Xx Dark Wizard xX
...it doesn't apply to the library directly, per say... it applies how to show a link to people in which they can see the showcode browser

- GhostAnime
In response to GhostAnime
I know it does, it works fine, it doesent hilight. Thats all i wanted. But thank's for the help.
In response to Xx Dark Wizard xX
I was replying to Wizkidd0123.
In response to CaptFalcon33035
any help here? (bump)
Page: 1 2