1. jerone

    21.07.2008 19:38

    Hello

    I'm using your script for some time now, and I still love it.
    Dho below I've got some improvements/suggestions/questions:

    Improvements:
    - you should really use prototype instead of functions, it's faster and better js.
    - document.write is old school; use DOM injection.

    Suggestions:
    - add tab convert; IE doesn't understand tabs :(, so everything is outlined left. Beside that, now it's possible to choose your preferred tab length (e.g. 4 or 8).
    - personally I think it's more clearer if you make separate files for every language. I don't see any point in putting some languages in one file and leave others out. It's much easier to change things if every language has its own file.
    - add the version to the files. There are no version numbers in the files, so when I check for updates I'm not sure and I have to compare the source.
    - please translate the documentation to English (I can't read Russian, and online translation sucks).

    Questions:
    - what method has priority: defaultMode or additional modes?
    - is it possible to add the defaultMode after an additional mode, so I can use there classnames?

    Currently I'm redoing the whole javascript file and make it totally complete (not yet online). Also I've made a new style (only js) the same as Dreamweaver 8. While doing so, I encouraged some problems:
    - in Javascript for example there are words which can mean 2 things. for example:
    'Date' can be an object —> 'Date.prototype.doSomething'
    or
    'Date()' can be a function which returns the current date.
    What you suggest is the best solution for this: adjust the lexems for the defaultMode (have to recheck every word then) or add a new mode (then I can't use the same classname).

    I hope I made a little bit sense.
    Please give your comments.
    Beside all above; keep up the great work!

    gr J
  2. Иван Сагалаев

    22.07.2008 01:29

    Hi! Thanks for such elaborate response!

    you should really use prototype instead of functions, it's faster and better js

    Well... I could argue about "better" :-). I don't need a prototype here architecturally because I have a single instance of the library object. What's the point of delegating attribute to prototype when they can live in the object itself? Also, making all functions attributes of prototype effectively makes them all public. And I want a separation between public interface (highlightBlock, initHighlighting) and implementation.

    As for faster I'm not sure. Accessing attributes in a prototype requires two lookups: first in an object, second in a prototype. Can you suggest a test that will show that prototype-bound methods are faster?

    document.write is old school; use DOM injection.

    I have a better idea :-). Instead of loading script files dynamically at runtime I think I'll make a smart download page where users could pick languages they want and get them all in a single file, compressed.

    add tab convert; IE doesn't understand tabs :(, so everything is outlined left. Beside that, now it's possible to choose your preferred tab length (e.g. 4 or 8).

    Was it you that already suggested it? :-)

    However, if, as you say, IE does this ugly thing it really makes sense to convert them to spaces. I'll think about it.

    I don't see any point in putting some languages in one file and leave others out

    The idea is to pack commonly used languages into one file so that in most cases only one or two files gets loaded. Loading many files is really degrading performance even if they are all cached and browser just gets "304 Not Modified" for all of them. But in practice it doesn't work as good as I hoped. The solution is what I mentioned above: monolith custom built packages.

    add the version to the files. There are no version numbers in the files, so when I check for updates I'm not sure and I have to compare the source

    If you're using released zip's you can look up a version number in a readme. If you want to keep track of updates it's actually better to make checkout from svn://softwaremaniacs.org/highlight/ and then you have the whole history.

    please translate the documentation to English

    Yeah, it's a long overdue task that I still can't find the time for... Sorry. But don't loose hope! I believe I'll get to it in the end.

    what method has priority: defaultMode or additional modes? is it possible to add the defaultMode after an additional mode, so I can use there classnames?

    They don't have a particular priority. A language object just contains definitions of the modes and they can refer to each other independent of their interlocation. "defaultMode" is default in a sense that when parser starts parsing a source it uses defaultMode from the beginning.

    Currently I'm redoing the whole javascript file and make it totally complete

    This is interesting. Currently the only two languages that parse to some extent all the body are CSS and Lisp because they both have very simple basic syntax. I'm afraid that making a complete parser for more traditionally shaped language like Javascript will result in a very big definition. How big is yours now?

    in Javascript for example there are words which can mean 2 things. for example: 'Date' can be an object —> 'Date.prototype.doSomething' or 'Date()' can be a function which returns the current date.

    AFAIK it's the same thing anyway. Function are object factories in javascript and Date() just constructs an instance of a Date object.

    What you suggest is the best solution for this: adjust the lexems for the defaultMode (have to recheck every word then) or add a new mode (then I can't use the same classname).

    Here I don't really get what you mean :-). I don't know what's in your default mode and how you're going to distinguish those things (apart from my point that I think you shouldn't do it).

  3. jerone

    22.07.2008 22:37

    Hey Иван Сагалаев,

    Thanks for taking time to reply.

    About that prototyping; I see your point. Ignore my suggestion.
    I have a better idea :-). Instead of loading script files dynamically at runtime I think I'll make a smart download page where users could pick languages they want and get them all in a single file, compressed.
    If you still keep the original also available, it's a good idea.
    Was it you that already suggested it? :-)
    However, if, as you say, IE does this ugly thing it really makes sense to convert them to spaces. I'll think about it.
    Yes that was me before. :P
    On my site I've added a simple documentation on where to add what to fix this 'bug' (see below).
    Maybe this should only be executed when in IE, I'm still thinking about this.
    If you're using released zip's you can look up a version number in a readme. If you want to keep track of updates it's actually better to make checkout from svn://softwaremaniacs.org/highlight/ and then you have the whole history.
    I never figured out how svn works. Anyways I just thought that you could add "version 4.2.1" to the comment above in the .js file. It's a stupid/simple idea.
    Yeah, it's a long overdue task that I still can't find the time for... Sorry. But don't loose hope! I believe I'll get to it in the end.
    :)
    They don't have a particular priority. A language object just contains definitions of the modes and they can refer to each other independent of their interlocation. "defaultMode" is default in a sense that when parser starts parsing a source it uses defaultMode from the beginning.
    I used the wrong words;
    with the defaultMode, which has priority: 'contains' or 'keywords'?
    And the answer is...: 'contains'. I did some tests and contains always has priority above the reserved keywords.
    This is interesting. Currently the only two languages that parse to some extent all the body are CSS and Lisp because they both have very simple basic syntax. I'm afraid that making a complete parser for more traditionally shaped language like Javascript will result in a very big definition. How big is yours now?
    Just 6kb.
    AFAIK it's the same thing anyway. Function are object factories in javascript and Date() just constructs an instance of a Date object.
    Date() returns the current date, but Date.prototype.doSomething can be a custom function. Aldo they are from the same object, they do other things and I've given them both another className.

    Ignore my last question :p

    I've put all my code improvements online on my site: http://jervw.freehostia.com/articles/art019/highlight.html.
    It contains the whole new javascript keywords file, a Macromedia Dreamweaver 8 style (currently for javascript only) and the fix for tabs.
    Check it out and take what you want to use. It isn't perfect yet and there are some small flaws.

    gr J

    ps. I've also got some little additions for CSS and the Dreamweaver 8 style for it; I let you know when it's finished.
  4. Иван Сагалаев

    23.07.2008 13:10

    I never figured out how svn works. Anyways I just thought that you could add "version 4.2.1" to the comment above in the .js file. It's a stupid/simple idea.

    I'm mostly reluctant because I currently update versions in 3 places and it's already got tiresome :-). And anyway svn (or any version control system, for that matter) is really a better way of doing things especially if you want to contribute, because merging changes from different people manually is almost impossible.

    I used the wrong words; with the defaultMode, which has priority: 'contains' or 'keywords'?

    For any mode "contains" is searched first because parser should have a chance to switch to another mode before it will look for end of current mode or any illegal content for it. Keywords are parsed last, in a second pass.

    I'm afraid that making a complete parser for more traditionally shaped language like Javascript will result in a very big definition. How big is yours now?

    Just 6kb.

    Great! I'll look into it for the next version. Thanks!

  5. jerone

    24.07.2008 01:36

    I'm going to check that svn this weekend.

    When rechecking the code in other browsers I found a bug in IE. So I updated my code with a fix [v1.1].
    Also I added a new part with CSS additions as I mentioned above. Check that also out.

    gr J

bbcode