Skip to content

Commit

Permalink
Fix formatToken() callback to process only non-empty tokens (Project-…
Browse files Browse the repository at this point in the history
…OSRM#271)

* Fix formatToken() callback to process only non-empty tokens

And also to don't handle 'name' tokens so it's called before final instruction text formatting and grammar rules applying

* Exclude prepending articles/prepositions from French names
  • Loading branch information
yuryleb authored and danpat committed Jul 28, 2018
1 parent 331513b commit 9009d06
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/itinerary_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ module.exports = function (language) {
return osrmTextInstructions.compile(language, step, {
formatToken : function(token, value) {
// enclose {way_name}, {rotary_name}, {destination} and {exit} vars with <b>..</b>
switch (token) {
case 'name':
case 'way_name':
case 'rotary_name':
case 'destination':
case 'exit':
return '<b>' + value + '</b>';
if (value) {
switch (token) {
case 'way_name':
case 'rotary_name':
case 'waypoint_name':
case 'destination':
case 'exit':
// Exclude prepending articles/prepositions from French names
return value.replace(/^((à )|(au )|(aux )|(le rond-point ))?((d)|(de )|(des )|(du ))?((l)|(la )|(le )|(les ))?/,
'$&<b>') + '</b>';
}
}
return value;
}
Expand Down

0 comments on commit 9009d06

Please sign in to comment.