Menu

#50 auto detect language

open
nobody
None
3
2007-10-17
2007-09-25
No

codepress should automatically detect javascript / php / asp / html and css in html/ php files.

Discussion

  • Nobody/Anonymous

    Logged In: NO

    do you mean some kind of parsing ?!?

     
  • Adam Jimenez

    Adam Jimenez - 2007-09-26

    Logged In: YES
    user_id=1871003
    Originator: YES

    it should detect <script> tags, <? tags and <style> tags - and highlight the content accordingly.

     
  • Martin Daniel Kirk

    Logged In: YES
    user_id=577658
    Originator: NO

    Well - I've created my own beta version of a Developer Enviroment, using Codepress - im using ASP as serverside component for reading/writing/file-listing - and are using the file extension to guess the format:

    function GuessExtension(fname)
    ext = right(fname,3)
    if ext = ".cs" then
    GuessExtension = "csharp"
    elseif ext = "css" then
    GuessExtension = "css"
    elseif ext = "htm" or ext = "tml" or ext = "xml" or ext = "xsl" or ext = "xsc" then
    GuessExtension = "html"
    elseif ext = "ava" then
    GuessExtension = "java"
    elseif ext = ".js" then
    GuessExtension = "javascript"
    elseif ext = "txt" then
    GuessExtension = "text"
    elseif ext = "sql" then
    GuessExtension = "sql"
    elseif ext = "asp" then
    GuessExtension = "vbscript"
    else
    GuessExtension = "generic"
    end if
    end function

    --------
    i have then created a AJAX module that takes 3 parameters :
    1. An URL that locates the file
    2. An Action => "openfile", "save", "saveas", "loadlist"
    3. Multiple-Use Parameter => being either the Language of file or the Code to save

    in order to fix any mistaken language, ive created a <select> to shift language:

    <select id="Lang" onchange="change()">
    <option value="csharp">C#</option>
    <option value="css">CSS</option>
    <option value="generic">Generic</option>
    <option selected="selected" value="html">HTML</option>
    <option value="java">Java</option>
    <option value="javascript">JavaScript</option>
    <option value="perl">Perl</option>
    <option value="ruby">Ruby</option>
    <option value="php">PHP</option>
    <option value="text">Text</option>
    <option value="sql">SQL</option>
    <option value="vbscript">VBScript</option>
    </select>

    and a function for doing it:

    function change(){
    var lang = byid("Lang").value;
    myCpWindow.edit( myCpWindow.getCode(), lang );
    }

    i hope this inspires you :)

     
  • pyrou

    pyrou - 2007-10-17
    • priority: 5 --> 3
     
  • pyrou

    pyrou - 2007-10-17

    Logged In: YES
    user_id=1695796
    Originator: NO

    looks really hard.

     
  • Martin Daniel Kirk

    Logged In: YES
    user_id=577658
    Originator: NO

    Try it out, at www.mdk-photo.com/Trial

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.