Server OAPIF nl2br template function

Introduce a new template function to replace nl with <br>
This commit is contained in:
Alessandro Pasotti 2019-11-05 13:55:08 +01:00
parent 8f52da7fdf
commit 8931d7256f
3 changed files with 10 additions and 2 deletions

View File

@ -68,14 +68,14 @@
{% if existsIn(param, "name") %}
<tr>
<td>{{ param.name }}</td>
<td class="small">{{ param.description }}</td>
<td class="small">{{ nl2br( param.description ) }}</td>
<td>{{ param.schema.type }}</td>
</tr>
{% else %}
{% for comp_param in component_parameter( param ) %}
<tr>
<td>{{ comp_param.name }}</td>
<td class="small">{{ comp_param.description }}</td>
<td class="small">{{ nl2br( comp_param.description ) }}</td>
<td>{{ comp_param.schema.type }}</td>
</tr>
{% endfor %}

View File

@ -359,6 +359,13 @@ void QgsServerOgcApiHandler::htmlDump( const json &data, const QgsServerApiConte
return QgsServerOgcApi::contentTypeToStdString( ct );
} );
// Replace newlines with <br>
env.add_callback( "nl2br", 1, [ = ]( Arguments & args )
{
QString text { QString::fromStdString( args.at( 0 )->get<std::string>( ) ) };
return text.replace( '\n', QLatin1String( "<br>" ) ).toStdString();
} );
// Returns a list of parameter component data from components -> parameters by ref name
// parameter( <ref object> )

View File

@ -181,6 +181,7 @@ class SERVER_EXPORT QgsServerOgcApiHandler
* static( "/style/black.css" ) will return something like "/wfs3/static/style/black.css".
* - links_filter( links, key, value ): Returns filtered links from a link list
* - content_type_name( content_type ): Returns a short name from a content type for example "text/html" will return "HTML"
* - nl2br( text ): Returns the input text with all newlines replaced by "<br>" tags
*
* \note not available in Python bindings
*/