Namespaces
Variants
Views
Actions

Template talk:source

From cppreference.com

[edit] Font looks different for C++ code

C source and C++ source look quite different on my machine

C code
C++ code

Firebug reveals the following rule for C++:

tt, code, pre, .cpp.source-cpp {
    font-family: DejaVuSansMono,"DejaVu Sans Mono",courier,monospace !important;
}

--Bazzy 09:02, 27 April 2012 (PDT)

Thanks for reporting this bug. I forgot to update the CSS when the C language was added. Since I use the DejaVu as default font, I couldn't see the difference. Hope this is now fixed. -- P12 13:29, 27 April 2012 (PDT)

[edit] Autolinking of library names

Hi, I'm trying to understand how the autolinking of library names works (e.g. in std::size_t) with a view to adding missing names (e.g. the new std::align_val_t). I've worked out that Template:source calls the magic word #tag:source ([[1]]), which then presumably invokes the <source> tag, which I'm guessing is the old Extension:SyntaxHighlight_GeSHi. Is there any way I can contribute to the list of recognised library names or should I just make requests? ed@catmur.co.uk (talk) 04:02, 6 September 2016 (PDT)

The list is MediaWiki:Geshi-keyword-list-cpp, which is generated from https://github.com/p12tic/cppreference-doc/blob/master/index-functions-cpp.xml --D41D8CD98F (talk) 05:54, 6 September 2016 (PDT)

[edit] Protected edit request: Parameter for leading spaces

Unfortunately, MediaWiki eats leading and trailing spaces on = parameters to templates and there's no real way around that. Meaning that this:

{{source| // Indent #include <iostream> }}
  // Indent
  #include <iostream>


looks very different from this:

{{source|1= // Indent #include <iostream> }}
// Indent
  #include <iostream>


As I said, there's no way around it, and since most code passed to {{source}} will contain equals signs, the second form is necessarily more common.

However, it is possible to add an optional parameter leading= to this template, that will insert the requisite number of spaces. In order to support this parameter, and make it possible to use the template like this:

{{source|leading=2|1= // Indent #include <iostream> }}
  // Indent
  #include <iostream>


Please change the template code from this:

<onlyinclude>{{#tag:source|{{{code|{{{1}}}}}}|lang={{{lang|{{get lang}}}}}}}</onlyinclude>
{{documentation}}

to this:

<onlyinclude>{{#tag:source|{{space|{{{leading|0}}}}}{{{code|{{{1}}}}}}|lang={{{lang|{{get lang}}}}}}}</onlyinclude>
{{documentation}}

Thanks.

(P.S> Just FYI, I'll be making a similar request at Template talk:example, to add code-leading= and output-leading= arguments that it passes to Template:source.) -- FeRDNYC (talk) 18:18, 3 July 2021 (PDT)