Raw Code Download: Difference between revisions

From Scribus Wiki
Jump to navigation Jump to search
No edit summary
 
(9 intermediate revisions by 3 users not shown)
Line 1: Line 1:
[[Category:Wiki_Help]]
[[Category:Wiki_Help]] [[Category:Scripts]]
This wiki is capable of letting users download raw code embedded into the pages. Please see [http://wiki.yobi.be/wiki/Mediawiki_RawFile Mediawiki_RawFile] for more details, especially the examples at the [http://wiki.yobi.be/wiki/Mediawiki_RawFile#Short_example Examples] page.
This wiki is capable of letting users download raw code embedded into the pages. Please see [http://wiki.yobi.be/wiki/Mediawiki_RawFile Mediawiki_RawFile] for more details, especially the examples at the [http://wiki.yobi.be/wiki/Mediawiki_RawFile#Short_example Examples] page.


In short, use either <nowiki><source lang=xxxxx></source></nowiki> tags where xxxxx is the language such as 'bash', 'python', 'cpp' and so on around your code snippets or for more power use the specially designed <nowiki>{{#fileanchor: myotherscript.sh}}</nowiki> and <nowiki>{{#filelink: myotherscript.sh}}</nowiki> templates as shown in the long example.
== With 'syntaxhighlight' tag ==


Here is a working example using code taken from [http://www.graphicslab.org/Blog/Adding-a-new-Command-to-the-Scribus-Scripter graphicslab.org]
In short, so as to cite python script code with proper syntax hilight, use the following tag <nowiki><syntaxhighlight lang='python'></nowiki> and close your cite with <nowiki></syntaxhighlight></nowiki>
THIS WORKS.


Exeample :
<syntaxhighlight lang='python'>
def getCSVdata():
    """opens a csv file, reads it in and returns a 2 dimensional list with the data"""
    csvfile = scribus.fileDialog("csv2table :: open file", "*.csv")
    if csvfile != "":
        try:
            reader = csv.reader(file(csvfile))
            datalist=[]
            for row in reader:
                rowlist=[]
                for col in row:
                    rowlist.append(col)
                datalist.append(rowlist)
            return datalist
        except Exception,  e:
            scribus.messageBox("csv2table", "Could not open file %s"%e)
    else:
        sys.exit
</syntaxhighlight>
== With 'source' ==
* Use either <nowiki><source lang=xxxxx></source></nowiki> tags where xxxxx is the language such as 'bash', 'python', 'cpp' and so on around your code snippets
or for more power use the specially designed <nowiki>{{#fileanchor: myotherscript.sh}}</nowiki> and <nowiki>{{#filelink: myotherscript.sh}}</nowiki> templates as shown in the long example.


Save the following code as [{{#file: cmdtext.cpp}} cmdtext.cpp]
<source lang=cpp>
<source lang=cpp>


Line 16: Line 41:
\n\
\n\
Repeat the text of the text frame \"name\" n times.\n\
Repeat the text of the text frame \"name\" n times.\n\
If \"name\" is not given the currently selected item is used.\n\"
If \"name\" is not given the currently selected item is used.\n"
));
));
/*! Repeat text */
/*! Repeat text */
PyObject * scribus_repeattext(PyObject * /*self*/, PyObject * args);
PyObject * scribus_repeattext(PyObject * /*self*/, PyObject * args);
</source>
Let's save the following code [{{#file: myscript.sh}} as myscript.sh]
<source lang=bash>
#!/bin/bash
echo 'Hello world!'
exit 0
</source>
</source>

Latest revision as of 07:58, 25 September 2014

This wiki is capable of letting users download raw code embedded into the pages. Please see Mediawiki_RawFile for more details, especially the examples at the Examples page.

With 'syntaxhighlight' tag

In short, so as to cite python script code with proper syntax hilight, use the following tag <syntaxhighlight lang='python'> and close your cite with </syntaxhighlight> THIS WORKS.

Exeample :

def getCSVdata():
    """opens a csv file, reads it in and returns a 2 dimensional list with the data"""
    csvfile = scribus.fileDialog("csv2table :: open file", "*.csv")
    if csvfile != "":
        try:
            reader = csv.reader(file(csvfile))
            datalist=[]
            for row in reader:
                rowlist=[]
                for col in row:
                    rowlist.append(col)
                datalist.append(rowlist)
            return datalist
        except Exception,  e:
            scribus.messageBox("csv2table", "Could not open file %s"%e)
    else:
        sys.exit

With 'source'

  • Use either <source lang=xxxxx></source> tags where xxxxx is the language such as 'bash', 'python', 'cpp' and so on around your code snippets

or for more power use the specially designed {{#fileanchor: myotherscript.sh}} and {{#filelink: myotherscript.sh}} templates as shown in the long example.

/*! docstring */
PyDoc_STRVAR
(scribus_repeattext__doc__,
QT_TR_NOOP("repeatText(n, [\"name\"])\n\
\n\
Repeat the text of the text frame \"name\" n times.\n\
If \"name\" is not given the currently selected item is used.\n"
));
/*! Repeat text */
PyObject * scribus_repeattext(PyObject * /*self*/, PyObject * args);