From b59f28424cfba36015ff8f3ff3756e76f1cc0f88 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Wed, 27 Mar 2013 14:32:29 -0400 Subject: [PATCH] Translatable documentation, Fixes #1108 * Adds Marked * Fixes a global leak in toGeoJSON * Removes marked from package.json * Adds documentation to core.yaml * Removes stray console.log from tests --- Makefile | 2 + build.js | 17 - data/core.yaml | 237 +++++++ data/data_dev.js | 7 +- data/doc.json | 34 - data/doc/00-help.md | 13 - data/doc/01-editing-saving.md | 35 - data/doc/03-road.md | 55 -- data/doc/04-gps.md | 18 - data/doc/05-imagery.md | 16 - data/doc/06-addresses.md | 12 - data/doc/07-inspector.md | 36 -- data/doc/building.md | 43 -- data/locales.js | 76 ++- data/update_locales.js | 7 +- index.html | 1 + js/id/ui/help.js | 22 +- js/lib/marked.js | 1127 +++++++++++++++++++++++++++++++++ js/lib/togeojson.js | 2 +- package.json | 3 - test/spec/presets/preset.js | 2 - 21 files changed, 1444 insertions(+), 321 deletions(-) delete mode 100644 data/doc.json delete mode 100644 data/doc/00-help.md delete mode 100644 data/doc/01-editing-saving.md delete mode 100644 data/doc/03-road.md delete mode 100644 data/doc/04-gps.md delete mode 100644 data/doc/05-imagery.md delete mode 100644 data/doc/06-addresses.md delete mode 100644 data/doc/07-inspector.md delete mode 100644 data/doc/building.md create mode 100644 js/lib/marked.js diff --git a/Makefile b/Makefile index 54dd942a8..bf2ef7b67 100644 --- a/Makefile +++ b/Makefile @@ -30,6 +30,8 @@ data/data.js: $(DATA_FILES) js/lib/ohauth.js \ js/lib/rtree.js \ js/lib/sha.js \ + js/lib/togeojson.js \ + js/lib/marked.js \ js/id/start.js \ js/id/id.js \ js/id/connection.js \ diff --git a/build.js b/build.js index fd5f5f35f..33c9d94d7 100644 --- a/build.js +++ b/build.js @@ -2,7 +2,6 @@ var fs = require('fs'), path = require('path'), glob = require('glob'), YAML = require('js-yaml'), - marked = require('marked'), _ = require('./js/lib/lodash'), jsonschema = require('jsonschema'), fieldSchema = require('./data/presets/schema/field.json'), @@ -48,20 +47,6 @@ var translations = { presets: {} }; -function generateDocumentation() { - var docs = []; - glob.sync(__dirname + '/data/doc/*.md').forEach(function(file) { - var text = readtxt(file), - title = text.split('\n')[0] - .replace('#', '').trim(); - docs.push({ - html: marked(text.split('\n').slice(1).join('\n')), - title: title - }); - }); - fs.writeFileSync('data/doc.json', stringify(docs)); -} - function generateFields() { var fields = {}; glob.sync(__dirname + '/data/presets/fields/*.json').forEach(function(file) { @@ -101,7 +86,6 @@ function generatePresets() { fs.writeFileSync('data/presets.yaml', YAML.dump({en: {presets: translations}})); } -generateDocumentation(); generateFields(); generatePresets(); @@ -110,7 +94,6 @@ fs.writeFileSync('data/data.js', 'iD.data = ' + stringify({ discarded: r('discarded.json'), keys: r('keys.json'), imagery: r('imagery.json'), - doc: r('doc.json'), presets: { presets: rp('presets.json'), defaults: rp('defaults.json'), diff --git a/data/core.yaml b/data/core.yaml index 8271b9bcf..1c026b8b8 100644 --- a/data/core.yaml +++ b/data/core.yaml @@ -13,6 +13,7 @@ en: description: "Add restaurants, monuments, postal boxes or other points to the map." tail: Click on the map to add a point. browse: + title: Browse description: Pan and zoom the map. draw_area: @@ -189,3 +190,239 @@ en: drag_drop: "Drag and drop a .gpx file on the page" help: title: "Help" + help: | + # Help + + This is an editor for [OpenStreetMap](http://www.openstreetmap.org/), the + free and editable map of the world. You can use it to add and update + data in your area, making an open-source and open-data map of the world + better for everyone. + + Edits that you make on this map will be visible to everyone who uses + OpenStreetMap. In order to make an edit, you'll need a + [free OpenStreetMap account](https://www.openstreetmap.org/user/new). + + The [iD editor](http://ideditor.com/) is a collaborative project with [source + code available on GitHub](https://github.com/systemed/iD). + editing_saving: | + # Editing & Saving + + This editor is designed to work primarily online, and you're accessing + it through a website right now. + + ### Selecting Features + + To select a map feature, like a road or point of interest, click + on it on the map. This will highlight the selected feature, open a panel with + details about it, and show a menu of things you can do with the feature. + + Multiple features can be selected by holding the 'Shift' key, clicking, + and dragging on the map. This will select all features within the box + that's drawn, allowing you to do things with several features at once. + + ### Saving Edits + + When you make changes like editing roads, buildings, and places, these are + stored locally until you save them to the server. Don't worry if you make + a mistake - you can undo changes by clicking the undo button, and redo + changes by clicking the redo button. + + Click 'Save' to finish a group of edits - for instance, if you've completed + an area of town and would like to start on a new area. You'll have a chance + to review what you've done, and the editor supplies helpful suggestions + and warnings if something doesn't seem right about the changes. + + If everything looks good, you can enter a short comment explaining the change + you made, and click 'Save' again to post the changes + to [OpenStreetMap.org](http://www.openstreetmap.org/), where they are visible + to all other users and available for others to build and improve upon. + + If you can't finish your edits in one sitting, you can leave the editor + window and come back (on the same browser and computer), and the + editor application will offer to restore your work. + roads: | + # Roads + + You can create, fix, and delete roads with this editor. Roads can be all + kinds: paths, highways, trails, cycleways, and more - any often-crossed + segment should be mappable. + + ### Selecting + + Click on a road to select it. An outline should become visible, along + with a small tools menu on the map and a sidebar showing more information + about the road. + + ### Modifying + + Often you'll see roads that aren't aligned to the imagery behind them + or to a GPS track. You can adjust these roads so they are in the correct + place. + + First click on the road you want to change. This will highlight it and show + control points along it that you can drag to better locations. If + you want to add new control points for more detail, double-click a part + of the road without a point, and one will be added. + + If the road connects to another road, but doesn't properly connect on + the map, you can drag one of its control points onto the other road in + order to join them. Having roads connect is important for the map + and essential for providing driving directions. + + You can also click the 'Move' tool or press the `M` shortcut key to move the entire road at + one time, and then click again to save that movement. + + ### Deleting + + If a road is entirely incorrect - you can see that it doesn't exist in satellite + imagery and ideally have confirmed locally that it's not present - you can delete + it, which removes it from the map. Be cautious when deleting features - + like any other edit, the results are seen by everyone and satellite imagery + is often out of date, so the road could simply be newly built. + + You can delete a road by clicking on it to select it, then clicking the + trash can icon or pressing the 'Delete' key. + + ### Creating + + Found somewhere there should be a road but there isn't? Click the 'Line' + icon in the top-left of the editor or press the shortcut key `2` to start drawing + a line. + + Click on the start of the road on the map to start drawing. If the road + branches off from an existing road, start by clicking on the place where they connect. + + Then click on points along the road so that it follows the right path, according + to satellite imagery or GPS. If the road you are drawing crosses another road, connect + it by clicking on the intersection point. When you're done drawing, double-click + or press 'Return' or 'Enter' on your keyboard. + gps: | + # GPS + + GPS data is the most trusted source of data for OpenStreetMap. This editor + supports local traces - `.gpx` files on your local computer. You can collect + this kind of GPS trace with a number of smartphone applications as well as + personal GPS hardware. + + For information on how to perform a GPS survey, read + [Surveying with a GPS](http://learnosm.org/en/beginner/using-gps/). + + To use a GPX track for mapping, drag and drop the GPX file onto the map + editor. If it's recognized, it will be added to the map as a bright green + line. Click on the 'Background Settings' menu on the left side to enable, + disable, or zoom to this new GPX-powered layer. + + The GPX track isn't directly uploaded to OpenStreetMap - the best way to + use it is to draw on the map, using it as a guide for the new features that + you add. + imagery: | + # Imagery + + Aerial imagery is an important resource for mapping. A combination of + airplane flyovers, satellite views, and freely-compiled sources are available + in the editor under the 'Background Settings' menu on the left. + + By default a [Bing Maps](http://www.bing.com/maps/) satellite layer is + presented in the editor, but as you pan and zoom the map to new geographical + areas, new sources will become available. Some countries, like the United + States, France, and Denmark have very high-quality imagery available for some areas. + + Imagery is sometimes offset from the map data because of a mistake on the + imagery provider's side. If you see a lot of roads shifted from the background, + don't immediately move them all to match the background. Instead you can adjust + the imagery so that it matches the existing data by clicking 'Fix alignment' at + the bottom of the Background Settings UI. + addresses: | + # Addresses + + Addresses are some of the most useful information for the map. + + Although addresses are often represented as parts of streets, in OpenStreetMap + they're recorded as attributes of buildings and places along streets. + + You can add address information to places mapped as building outlines as well + as well as those mapped as single points. The optimal source of address + data is from an on-the-ground survey or personal knowledge - as with any + other feature, copying from commercial sources like Google Maps is strictly + forbidden. + inspector: | + # Using the Inspector + + The inspector is the user interface element on the right-hand side of the + page that appears when a feature is selected and allows you to edit its details. + + ### Selecting a Feature Type + + After you add a point, line, or area, you can choose what type of feature it + is, like whether it's a highway or residential road, supermarket or cafe. + The inspector will display buttons for common feature types, and you can + find others by typing what you're looking for in the search box. + + Click the 'i' in the bottom-right-hand corner of a feature type button to + learn more about it. Click a button to choose that type. + + ### Using Forms and Editing Tags + + After you choose a feature type, or when you select a feature that already + has a type assigned, the inspector will display fields with details about + the feature like its name and address. + + Below the fields you see, you can click icons to add other details, + like [Wikipedia](http://www.wikipedia.org/) information, wheelchair + access, and more. + + At the bottom of the inspector, click 'Additional tags' to add arbitrary + other tags to the element. [Taginfo](http://taginfo.openstreetmap.org/) is a + great resource for learn more about popular tag combinations. + + Changes you make in the inspector are automatically applied to the map. + You can undo them at any time by clicking the 'Undo' button. + + ### Closing the Inspector + + You can close the inspector by clicking the close button in the top-right, + pressing the 'Escape' key, or clicking on the map. + buildings: | + # Buildings + + OpenStreetMap is the world's largest database of buildings. You can create + and improve this database. + + ### Selecting + + You can select a building by clicking on its border. This will highlight the + building and open a small tools menu and a sidebar showing more information + about the building. + + ### Modifying + + Sometimes buildings are incorrectly placed or have incorrect tags. + + To move an entire building, select it, then click the 'Move' tool. Move your + mouse to shift the building, and click when it's correctly placed. + + To fix the specific shape of a building, click and drag the points that form + its border into better places. + + ### Creating + + One of the main questions around adding buildings to the map is that + OpenStreetMap records buildings both as shapes and points. The rule of thumb + is to _map a building as a shape whenever possible_, and map companies, homes, + amenities, and other things that operate out of buildings as points placed + within the building shape. + + Start drawing a building as a shape by clicking the 'Area' button in the top + left of the interface, and end it either by pressing 'Return' on your keyboard + or clicking on the first point drawn to close the shape. + + ### Deleting + + If a building is entirely incorrect - you can see that it doesn't exist in satellite + imagery and ideally have confirmed locally that it's not present - you can delete + it, which removes it from the map. Be cautious when deleting features - + like any other edit, the results are seen by everyone and satellite imagery + is often out of date, so the road could simply be newly built. + + You can delete a building by clicking on it to select it, then clicking the + trash can icon or pressing the 'Delete' key. diff --git a/data/data_dev.js b/data/data_dev.js index 6968c7d6a..c3246d66a 100644 --- a/data/data_dev.js +++ b/data/data_dev.js @@ -12,8 +12,8 @@ iD.data = { path + 'data/presets/presets.json', path + 'data/presets/defaults.json', path + 'data/presets/categories.json', - path + 'data/presets/fields.json', - path + 'data/doc.json'], d3.json, function (err, data) { + path + 'data/presets/fields.json' + ], d3.json, function (err, data) { iD.data = { deprecated: data[0], @@ -25,8 +25,7 @@ iD.data = { defaults: data[5], categories: data[6], fields: data[7] - }, - doc: data[8] + } }; callback(); diff --git a/data/doc.json b/data/doc.json deleted file mode 100644 index ee19fca1a..000000000 --- a/data/doc.json +++ /dev/null @@ -1,34 +0,0 @@ -[ - { - "html": "

This is an editor for OpenStreetMap, the\nfree and editable map of the world. You can use it to add and update\ndata in your area, making an open-source and open-data map of the world\nbetter for everyone.

\n

Edits that you make on this map will be visible to everyone who uses\nOpenStreetMap. In order to make an edit, you'll need a\nfree OpenStreetMap account.

\n

The iD editor is a collaborative project with source\ncode available on GitHub.

\n", - "title": "Help" - }, - { - "html": "

This editor is designed to work primarily online, and you're accessing\nit through a website right now.

\n

Selecting Features

\n

To select a map feature, like a road or point of interest, click\non it on the map. This will highlight the selected feature, open a panel with\ndetails about it, and show a menu of things you can do with the feature.

\n

Multiple features can be selected by holding the 'Shift' key, clicking,\nand dragging on the map. This will select all features within the box\nthat's drawn, allowing you to do things with several features at once.

\n

Saving Edits

\n

When you make changes like editing roads, buildings, and places, these are\nstored locally until you save them to the server. Don't worry if you make\na mistake - you can undo changes by clicking the undo button, and redo\nchanges by clicking the redo button.

\n

Click 'Save' to finish a group of edits - for instance, if you've completed\nan area of town and would like to start on a new area. You'll have a chance\nto review what you've done, and the editor supplies helpful suggestions\nand warnings if something doesn't seem right about the changes.

\n

If everything looks good, you can enter a short comment explaining the change\nyou made, and click 'Save' again to post the changes\nto OpenStreetMap.org, where they are visible\nto all other users and available for others to build and improve upon.

\n

If you can't finish your edits in one sitting, you can leave the editor\nwindow and come back (on the same browser and computer), and the\neditor application will offer to restore your work.

\n", - "title": "Editing & Saving" - }, - { - "html": "

You can create, fix, and delete roads with this editor. Roads can be all\nkinds: paths, highways, trails, cycleways, and more - any often-crossed\nsegment should be mappable.

\n

Selecting

\n

Click on a road to select it. An outline should become visible, along\nwith a small tools menu on the map and a sidebar showing more information\nabout the road.

\n

Modifying

\n

Often you'll see roads that aren't aligned to the imagery behind them\nor to a GPS track. You can adjust these roads so they are in the correct\nplace.

\n

First click on the road you want to change. This will highlight it and show\ncontrol points along it that you can drag to better locations. If\nyou want to add new control points for more detail, double-click a part\nof the road without a point, and one will be added.

\n

If the road connects to another road, but doesn't properly connect on\nthe map, you can drag one of its control points onto the other road in\norder to join them. Having roads connect is important for the map\nand essential for providing driving directions.

\n

You can also click the 'Move' tool or press the M shortcut key to move the entire road at\none time, and then click again to save that movement.

\n

Deleting

\n

If a road is entirely incorrect - you can see that it doesn't exist in satellite\nimagery and ideally have confirmed locally that it's not present - you can delete\nit, which removes it from the map. Be cautious when deleting features -\nlike any other edit, the results are seen by everyone and satellite imagery\nis often out of date, so the road could simply be newly built.

\n

You can delete a road by clicking on it to select it, then clicking the\ntrash can icon or pressing the 'Delete' key.

\n

Creating

\n

Found somewhere there should be a road but there isn't? Click the 'Line'\nicon in the top-left of the editor or press the shortcut key 2 to start drawing\na line.

\n

Click on the start of the road on the map to start drawing. If the road\nbranches off from an existing road, start by clicking on the place where they connect.

\n

Then click on points along the road so that it follows the right path, according\nto satellite imagery or GPS. If the road you are drawing crosses another road, connect\nit by clicking on the intersection point. When you're done drawing, double-click\nor press 'Return' or 'Enter' on your keyboard.

\n", - "title": "Roads" - }, - { - "html": "

GPS data is the most trusted source of data for OpenStreetMap. This editor\nsupports local traces - .gpx files on your local computer. You can collect\nthis kind of GPS trace with a number of smartphone applications as well as\npersonal GPS hardware.

\n

For information on how to perform a GPS survey, read\nSurveying with a GPS.

\n

To use a GPX track for mapping, drag and drop the GPX file onto the map\neditor. If it's recognized, it will be added to the map as a bright green\nline. Click on the 'Background Settings' menu on the left side to enable,\ndisable, or zoom to this new GPX-powered layer.

\n

The GPX track isn't directly uploaded to OpenStreetMap - the best way to\nuse it is to draw on the map, using it as a guide for the new features that\nyou add.

\n", - "title": "GPS" - }, - { - "html": "

Aerial imagery is an important resource for mapping. A combination of\nairplane flyovers, satellite views, and freely-compiled sources are available\nin the editor under the 'Background Settings' menu on the left.

\n

By default a Bing Maps satellite layer is\npresented in the editor, but as you pan and zoom the map to new geographical\nareas, new sources will become available. Some countries, like the United\nStates, France, and Denmark have very high-quality imagery available for some areas.

\n

Imagery is sometimes offset from the map data because of a mistake on the\nimagery provider's side. If you see a lot of roads shifted from the background,\ndon't immediately move them all to match the background. Instead you can adjust\nthe imagery so that it matches the existing data by clicking 'Fix alignment' at\nthe bottom of the Background Settings UI.

\n", - "title": "Imagery" - }, - { - "html": "

Addresses are some of the most useful information for the map.

\n

Although addresses are often represented as parts of streets, in OpenStreetMap\nthey're recorded as attributes of buildings and places along streets.

\n

You can add address information to places mapped as building outlines as well\nas well as those mapped as single points. The optimal source of address\ndata is from an on-the-ground survey or personal knowledge - as with any\nother feature, copying from commercial sources like Google Maps is strictly\nforbidden.

\n", - "title": "Addresses" - }, - { - "html": "

The inspector is the user interface element on the right-hand side of the\npage that appears when a feature is selected and allows you to edit its details.

\n

Selecting a Feature Type

\n

After you add a point, line, or area, you can choose what type of feature it\nis, like whether it's a highway or residential road, supermarket or cafe.\nThe inspector will display buttons for common feature types, and you can\nfind others by typing what you're looking for in the search box.

\n

Click the 'i' in the bottom-right-hand corner of a feature type button to\nlearn more about it. Click a button to choose that type.

\n

Using Forms and Editing Tags

\n

After you choose a feature type, or when you select a feature that already\nhas a type assigned, the inspector will display fields with details about\nthe feature like its name and address.

\n

Below the fields you see, you can click icons to add other details,\nlike Wikipedia information, wheelchair\naccess, and more.

\n

At the bottom of the inspector, click 'Additional tags' to add arbitrary\nother tags to the element. Taginfo is a\ngreat resource for learn more about popular tag combinations.

\n

Changes you make in the inspector are automatically applied to the map.\nYou can undo them at any time by clicking the 'Undo' button.

\n

Closing the Inspector

\n

You can close the inspector by clicking the close button in the top-right,\npressing the 'Escape' key, or clicking on the map.

\n", - "title": "Using the Inspector" - }, - { - "html": "

OpenStreetMap is the world's largest database of buildings. You can create\nand improve this database.

\n

Selecting

\n

You can select a building by clicking on its border. This will highlight the\nbuilding and open a small tools menu and a sidebar showing more information\nabout the building.

\n

Modifying

\n

Sometimes buildings are incorrectly placed or have incorrect tags.

\n

To move an entire building, select it, then click the 'Move' tool. Move your\nmouse to shift the building, and click when it's correctly placed.

\n

To fix the specific shape of a building, click and drag the points that form\nits border into better places.

\n

Creating

\n

One of the main questions around adding buildings to the map is that\nOpenStreetMap records buildings both as shapes and points. The rule of thumb\nis to map a building as a shape whenever possible, and map companies, homes,\namenities, and other things that operate out of buildings as points placed\nwithin the building shape.

\n

Start drawing a building as a shape by clicking the 'Area' button in the top\nleft of the interface, and end it either by pressing 'Return' on your keyboard\nor clicking on the first point drawn to close the shape.

\n

Deleting

\n

If a building is entirely incorrect - you can see that it doesn't exist in satellite\nimagery and ideally have confirmed locally that it's not present - you can delete\nit, which removes it from the map. Be cautious when deleting features -\nlike any other edit, the results are seen by everyone and satellite imagery\nis often out of date, so the road could simply be newly built.

\n

You can delete a building by clicking on it to select it, then clicking the\ntrash can icon or pressing the 'Delete' key.

\n", - "title": "Buildings" - } -] \ No newline at end of file diff --git a/data/doc/00-help.md b/data/doc/00-help.md deleted file mode 100644 index e6d05571c..000000000 --- a/data/doc/00-help.md +++ /dev/null @@ -1,13 +0,0 @@ -# Help - -This is an editor for [OpenStreetMap](http://www.openstreetmap.org/), the -free and editable map of the world. You can use it to add and update -data in your area, making an open-source and open-data map of the world -better for everyone. - -Edits that you make on this map will be visible to everyone who uses -OpenStreetMap. In order to make an edit, you'll need a -[free OpenStreetMap account](https://www.openstreetmap.org/user/new). - -The [iD editor](http://ideditor.com/) is a collaborative project with [source -code available on GitHub](https://github.com/systemed/iD). diff --git a/data/doc/01-editing-saving.md b/data/doc/01-editing-saving.md deleted file mode 100644 index 45e634527..000000000 --- a/data/doc/01-editing-saving.md +++ /dev/null @@ -1,35 +0,0 @@ -# Editing & Saving - -This editor is designed to work primarily online, and you're accessing -it through a website right now. - -### Selecting Features - -To select a map feature, like a road or point of interest, click -on it on the map. This will highlight the selected feature, open a panel with -details about it, and show a menu of things you can do with the feature. - -Multiple features can be selected by holding the 'Shift' key, clicking, -and dragging on the map. This will select all features within the box -that's drawn, allowing you to do things with several features at once. - -### Saving Edits - -When you make changes like editing roads, buildings, and places, these are -stored locally until you save them to the server. Don't worry if you make -a mistake - you can undo changes by clicking the undo button, and redo -changes by clicking the redo button. - -Click 'Save' to finish a group of edits - for instance, if you've completed -an area of town and would like to start on a new area. You'll have a chance -to review what you've done, and the editor supplies helpful suggestions -and warnings if something doesn't seem right about the changes. - -If everything looks good, you can enter a short comment explaining the change -you made, and click 'Save' again to post the changes -to [OpenStreetMap.org](http://www.openstreetmap.org/), where they are visible -to all other users and available for others to build and improve upon. - -If you can't finish your edits in one sitting, you can leave the editor -window and come back (on the same browser and computer), and the -editor application will offer to restore your work. diff --git a/data/doc/03-road.md b/data/doc/03-road.md deleted file mode 100644 index 90d89e09b..000000000 --- a/data/doc/03-road.md +++ /dev/null @@ -1,55 +0,0 @@ -# Roads - -You can create, fix, and delete roads with this editor. Roads can be all -kinds: paths, highways, trails, cycleways, and more - any often-crossed -segment should be mappable. - -### Selecting - -Click on a road to select it. An outline should become visible, along -with a small tools menu on the map and a sidebar showing more information -about the road. - -### Modifying - -Often you'll see roads that aren't aligned to the imagery behind them -or to a GPS track. You can adjust these roads so they are in the correct -place. - -First click on the road you want to change. This will highlight it and show -control points along it that you can drag to better locations. If -you want to add new control points for more detail, double-click a part -of the road without a point, and one will be added. - -If the road connects to another road, but doesn't properly connect on -the map, you can drag one of its control points onto the other road in -order to join them. Having roads connect is important for the map -and essential for providing driving directions. - -You can also click the 'Move' tool or press the `M` shortcut key to move the entire road at -one time, and then click again to save that movement. - -### Deleting - -If a road is entirely incorrect - you can see that it doesn't exist in satellite -imagery and ideally have confirmed locally that it's not present - you can delete -it, which removes it from the map. Be cautious when deleting features - -like any other edit, the results are seen by everyone and satellite imagery -is often out of date, so the road could simply be newly built. - -You can delete a road by clicking on it to select it, then clicking the -trash can icon or pressing the 'Delete' key. - -### Creating - -Found somewhere there should be a road but there isn't? Click the 'Line' -icon in the top-left of the editor or press the shortcut key `2` to start drawing -a line. - -Click on the start of the road on the map to start drawing. If the road -branches off from an existing road, start by clicking on the place where they connect. - -Then click on points along the road so that it follows the right path, according -to satellite imagery or GPS. If the road you are drawing crosses another road, connect -it by clicking on the intersection point. When you're done drawing, double-click -or press 'Return' or 'Enter' on your keyboard. diff --git a/data/doc/04-gps.md b/data/doc/04-gps.md deleted file mode 100644 index bb412c3ed..000000000 --- a/data/doc/04-gps.md +++ /dev/null @@ -1,18 +0,0 @@ -# GPS - -GPS data is the most trusted source of data for OpenStreetMap. This editor -supports local traces - `.gpx` files on your local computer. You can collect -this kind of GPS trace with a number of smartphone applications as well as -personal GPS hardware. - -For information on how to perform a GPS survey, read -[Surveying with a GPS](http://learnosm.org/en/beginner/using-gps/). - -To use a GPX track for mapping, drag and drop the GPX file onto the map -editor. If it's recognized, it will be added to the map as a bright green -line. Click on the 'Background Settings' menu on the left side to enable, -disable, or zoom to this new GPX-powered layer. - -The GPX track isn't directly uploaded to OpenStreetMap - the best way to -use it is to draw on the map, using it as a guide for the new features that -you add. diff --git a/data/doc/05-imagery.md b/data/doc/05-imagery.md deleted file mode 100644 index cda226164..000000000 --- a/data/doc/05-imagery.md +++ /dev/null @@ -1,16 +0,0 @@ -# Imagery - -Aerial imagery is an important resource for mapping. A combination of -airplane flyovers, satellite views, and freely-compiled sources are available -in the editor under the 'Background Settings' menu on the left. - -By default a [Bing Maps](http://www.bing.com/maps/) satellite layer is -presented in the editor, but as you pan and zoom the map to new geographical -areas, new sources will become available. Some countries, like the United -States, France, and Denmark have very high-quality imagery available for some areas. - -Imagery is sometimes offset from the map data because of a mistake on the -imagery provider's side. If you see a lot of roads shifted from the background, -don't immediately move them all to match the background. Instead you can adjust -the imagery so that it matches the existing data by clicking 'Fix alignment' at -the bottom of the Background Settings UI. diff --git a/data/doc/06-addresses.md b/data/doc/06-addresses.md deleted file mode 100644 index 0250e8cd3..000000000 --- a/data/doc/06-addresses.md +++ /dev/null @@ -1,12 +0,0 @@ -# Addresses - -Addresses are some of the most useful information for the map. - -Although addresses are often represented as parts of streets, in OpenStreetMap -they're recorded as attributes of buildings and places along streets. - -You can add address information to places mapped as building outlines as well -as well as those mapped as single points. The optimal source of address -data is from an on-the-ground survey or personal knowledge - as with any -other feature, copying from commercial sources like Google Maps is strictly -forbidden. diff --git a/data/doc/07-inspector.md b/data/doc/07-inspector.md deleted file mode 100644 index 4169d5cb8..000000000 --- a/data/doc/07-inspector.md +++ /dev/null @@ -1,36 +0,0 @@ -# Using the Inspector - -The inspector is the user interface element on the right-hand side of the -page that appears when a feature is selected and allows you to edit its details. - -### Selecting a Feature Type - -After you add a point, line, or area, you can choose what type of feature it -is, like whether it's a highway or residential road, supermarket or cafe. -The inspector will display buttons for common feature types, and you can -find others by typing what you're looking for in the search box. - -Click the 'i' in the bottom-right-hand corner of a feature type button to -learn more about it. Click a button to choose that type. - -### Using Forms and Editing Tags - -After you choose a feature type, or when you select a feature that already -has a type assigned, the inspector will display fields with details about -the feature like its name and address. - -Below the fields you see, you can click icons to add other details, -like [Wikipedia](http://www.wikipedia.org/) information, wheelchair -access, and more. - -At the bottom of the inspector, click 'Additional tags' to add arbitrary -other tags to the element. [Taginfo](http://taginfo.openstreetmap.org/) is a -great resource for learn more about popular tag combinations. - -Changes you make in the inspector are automatically applied to the map. -You can undo them at any time by clicking the 'Undo' button. - -### Closing the Inspector - -You can close the inspector by clicking the close button in the top-right, -pressing the 'Escape' key, or clicking on the map. diff --git a/data/doc/building.md b/data/doc/building.md deleted file mode 100644 index 5a634de0d..000000000 --- a/data/doc/building.md +++ /dev/null @@ -1,43 +0,0 @@ -# Buildings - -OpenStreetMap is the world's largest database of buildings. You can create -and improve this database. - -### Selecting - -You can select a building by clicking on its border. This will highlight the -building and open a small tools menu and a sidebar showing more information -about the building. - -### Modifying - -Sometimes buildings are incorrectly placed or have incorrect tags. - -To move an entire building, select it, then click the 'Move' tool. Move your -mouse to shift the building, and click when it's correctly placed. - -To fix the specific shape of a building, click and drag the points that form -its border into better places. - -### Creating - -One of the main questions around adding buildings to the map is that -OpenStreetMap records buildings both as shapes and points. The rule of thumb -is to _map a building as a shape whenever possible_, and map companies, homes, -amenities, and other things that operate out of buildings as points placed -within the building shape. - -Start drawing a building as a shape by clicking the 'Area' button in the top -left of the interface, and end it either by pressing 'Return' on your keyboard -or clicking on the first point drawn to close the shape. - -### Deleting - -If a building is entirely incorrect - you can see that it doesn't exist in satellite -imagery and ideally have confirmed locally that it's not present - you can delete -it, which removes it from the map. Be cautious when deleting features - -like any other edit, the results are seen by everyone and satellite imagery -is often out of date, so the road could simply be newly built. - -You can delete a building by clicking on it to select it, then clicking the -trash can icon or pressing the 'Delete' key. diff --git a/data/locales.js b/data/locales.js index d48e24853..e3df50cb8 100644 --- a/data/locales.js +++ b/data/locales.js @@ -139,7 +139,7 @@ locale.en = { "nothing_to_redo": "Nothing to redo.", "just_edited": "You just edited OpenStreetMap!", "browser_notice": "This editor is supported in Firefox, Chrome, Safari, Opera, and Internet Explorer 9 and above. Please upgrade your browser or use Potlatch 2 to edit the map.", - "view_on_osm": "View on OSM", + "view_on_osm": "View on OSM →", "zoom_in_edit": "zoom in to edit the map", "logout": "logout", "report_a_bug": "report a bug", @@ -189,7 +189,7 @@ locale.en = { }, "restore": { "heading": "You have unsaved changes", - "description": "Do you wish to restore changes from a previous editing session?", + "description": "Do you wish to restore unsaved changes from a previous editing session?", "restore": "Restore", "reset": "Reset" }, @@ -202,7 +202,7 @@ locale.en = { "unsaved_changes": "You have unsaved changes" }, "splash": { - "welcome": "Welcome to the iD OpenStreetMap Editor", + "welcome": "Welcome to the iD OpenStreetMap editor", "text": "iD is a friendly but powerful tool for contributing to the world's best free world map. This is development version {version}. For more information see {website} and report bugs at {github}.", "walkthrough": "Start the walkthrough", "start": "Edit now" @@ -234,7 +234,15 @@ locale.en = { "drag_drop": "Drag and drop a .gpx file on the page" }, "help": { - "title": "Help" + "title": "Help", + "help": "# Help\n\nThis is an editor for [OpenStreetMap](http://www.openstreetmap.org/), the\nfree and editable map of the world. You can use it to add and update\ndata in your area, making an open-source and open-data map of the world\nbetter for everyone.\n\nEdits that you make on this map will be visible to everyone who uses\nOpenStreetMap. In order to make an edit, you'll need a\n[free OpenStreetMap account](https://www.openstreetmap.org/user/new).\n\nThe [iD editor](http://ideditor.com/) is a collaborative project with [source\ncode available on GitHub](https://github.com/systemed/iD).\n", + "editing_saving": "# Editing & Saving\n\nThis editor is designed to work primarily online, and you're accessing\nit through a website right now.\n\n### Selecting Features\n\nTo select a map feature, like a road or point of interest, click\non it on the map. This will highlight the selected feature, open a panel with\ndetails about it, and show a menu of things you can do with the feature.\n\nMultiple features can be selected by holding the 'Shift' key, clicking,\nand dragging on the map. This will select all features within the box\nthat's drawn, allowing you to do things with several features at once.\n\n### Saving Edits\n\nWhen you make changes like editing roads, buildings, and places, these are\nstored locally until you save them to the server. Don't worry if you make\na mistake - you can undo changes by clicking the undo button, and redo\nchanges by clicking the redo button.\n\nClick 'Save' to finish a group of edits - for instance, if you've completed\nan area of town and would like to start on a new area. You'll have a chance\nto review what you've done, and the editor supplies helpful suggestions\nand warnings if something doesn't seem right about the changes.\n\nIf everything looks good, you can enter a short comment explaining the change\nyou made, and click 'Save' again to post the changes\nto [OpenStreetMap.org](http://www.openstreetmap.org/), where they are visible\nto all other users and available for others to build and improve upon.\n\nIf you can't finish your edits in one sitting, you can leave the editor\nwindow and come back (on the same browser and computer), and the\neditor application will offer to restore your work.\n", + "roads": "# Roads\n\nYou can create, fix, and delete roads with this editor. Roads can be all\nkinds: paths, highways, trails, cycleways, and more - any often-crossed\nsegment should be mappable.\n\n### Selecting\n\nClick on a road to select it. An outline should become visible, along\nwith a small tools menu on the map and a sidebar showing more information\nabout the road.\n\n### Modifying\n\nOften you'll see roads that aren't aligned to the imagery behind them\nor to a GPS track. You can adjust these roads so they are in the correct\nplace.\n\nFirst click on the road you want to change. This will highlight it and show\ncontrol points along it that you can drag to better locations. If\nyou want to add new control points for more detail, double-click a part\nof the road without a point, and one will be added.\n\nIf the road connects to another road, but doesn't properly connect on\nthe map, you can drag one of its control points onto the other road in\norder to join them. Having roads connect is important for the map\nand essential for providing driving directions.\n\nYou can also click the 'Move' tool or press the `M` shortcut key to move the entire road at\none time, and then click again to save that movement.\n\n### Deleting\n\nIf a road is entirely incorrect - you can see that it doesn't exist in satellite\nimagery and ideally have confirmed locally that it's not present - you can delete\nit, which removes it from the map. Be cautious when deleting features -\nlike any other edit, the results are seen by everyone and satellite imagery\nis often out of date, so the road could simply be newly built.\n\nYou can delete a road by clicking on it to select it, then clicking the\ntrash can icon or pressing the 'Delete' key.\n\n### Creating\n\nFound somewhere there should be a road but there isn't? Click the 'Line'\nicon in the top-left of the editor or press the shortcut key `2` to start drawing\na line.\n\nClick on the start of the road on the map to start drawing. If the road\nbranches off from an existing road, start by clicking on the place where they connect.\n\nThen click on points along the road so that it follows the right path, according\nto satellite imagery or GPS. If the road you are drawing crosses another road, connect\nit by clicking on the intersection point. When you're done drawing, double-click\nor press 'Return' or 'Enter' on your keyboard.\n", + "gps": "# GPS\n\nGPS data is the most trusted source of data for OpenStreetMap. This editor\nsupports local traces - `.gpx` files on your local computer. You can collect\nthis kind of GPS trace with a number of smartphone applications as well as\npersonal GPS hardware.\n\nFor information on how to perform a GPS survey, read\n[Surveying with a GPS](http://learnosm.org/en/beginner/using-gps/).\n\nTo use a GPX track for mapping, drag and drop the GPX file onto the map\neditor. If it's recognized, it will be added to the map as a bright green\nline. Click on the 'Background Settings' menu on the left side to enable,\ndisable, or zoom to this new GPX-powered layer.\n\nThe GPX track isn't directly uploaded to OpenStreetMap - the best way to\nuse it is to draw on the map, using it as a guide for the new features that\nyou add.\n", + "imagery": "# Imagery\n\nAerial imagery is an important resource for mapping. A combination of\nairplane flyovers, satellite views, and freely-compiled sources are available\nin the editor under the 'Background Settings' menu on the left.\n\nBy default a [Bing Maps](http://www.bing.com/maps/) satellite layer is\npresented in the editor, but as you pan and zoom the map to new geographical\nareas, new sources will become available. Some countries, like the United\nStates, France, and Denmark have very high-quality imagery available for some areas.\n\nImagery is sometimes offset from the map data because of a mistake on the\nimagery provider's side. If you see a lot of roads shifted from the background,\ndon't immediately move them all to match the background. Instead you can adjust\nthe imagery so that it matches the existing data by clicking 'Fix alignment' at\nthe bottom of the Background Settings UI.\n", + "addresses": "# Addresses\n\nAddresses are some of the most useful information for the map.\n\nAlthough addresses are often represented as parts of streets, in OpenStreetMap\nthey're recorded as attributes of buildings and places along streets.\n\nYou can add address information to places mapped as building outlines as well\nas well as those mapped as single points. The optimal source of address\ndata is from an on-the-ground survey or personal knowledge - as with any\nother feature, copying from commercial sources like Google Maps is strictly\nforbidden.\n", + "inspector": "# Using the Inspector\n\nThe inspector is the user interface element on the right-hand side of the\npage that appears when a feature is selected and allows you to edit its details.\n\n### Selecting a Feature Type\n\nAfter you add a point, line, or area, you can choose what type of feature it\nis, like whether it's a highway or residential road, supermarket or cafe.\nThe inspector will display buttons for common feature types, and you can\nfind others by typing what you're looking for in the search box.\n\nClick the 'i' in the bottom-right-hand corner of a feature type button to\nlearn more about it. Click a button to choose that type.\n\n### Using Forms and Editing Tags\n\nAfter you choose a feature type, or when you select a feature that already\nhas a type assigned, the inspector will display fields with details about\nthe feature like its name and address.\n\nBelow the fields you see, you can click icons to add other details,\nlike [Wikipedia](http://www.wikipedia.org/) information, wheelchair\naccess, and more.\n\nAt the bottom of the inspector, click 'Additional tags' to add arbitrary\nother tags to the element. [Taginfo](http://taginfo.openstreetmap.org/) is a\ngreat resource for learn more about popular tag combinations.\n\nChanges you make in the inspector are automatically applied to the map.\nYou can undo them at any time by clicking the 'Undo' button.\n\n### Closing the Inspector\n\nYou can close the inspector by clicking the close button in the top-right,\npressing the 'Escape' key, or clicking on the map.\n", + "buildings": "# Buildings\n\nOpenStreetMap is the world's largest database of buildings. You can create\nand improve this database.\n\n### Selecting\n\nYou can select a building by clicking on its border. This will highlight the\nbuilding and open a small tools menu and a sidebar showing more information\nabout the building.\n\n### Modifying\n\nSometimes buildings are incorrectly placed or have incorrect tags.\n\nTo move an entire building, select it, then click the 'Move' tool. Move your\nmouse to shift the building, and click when it's correctly placed.\n\nTo fix the specific shape of a building, click and drag the points that form\nits border into better places.\n\n### Creating\n\nOne of the main questions around adding buildings to the map is that\nOpenStreetMap records buildings both as shapes and points. The rule of thumb\nis to _map a building as a shape whenever possible_, and map companies, homes,\namenities, and other things that operate out of buildings as points placed\nwithin the building shape.\n\nStart drawing a building as a shape by clicking the 'Area' button in the top\nleft of the interface, and end it either by pressing 'Return' on your keyboard\nor clicking on the first point drawn to close the shape.\n\n### Deleting\n\nIf a building is entirely incorrect - you can see that it doesn't exist in satellite\nimagery and ideally have confirmed locally that it's not present - you can delete\nit, which removes it from the map. Be cautious when deleting features -\nlike any other edit, the results are seen by everyone and satellite imagery\nis often out of date, so the road could simply be newly built.\n\nYou can delete a building by clicking on it to select it, then clicking the\ntrash can icon or pressing the 'Delete' key.\n" }, "presets": { "fields": { @@ -1713,9 +1721,6 @@ locale.zh = { "in": "放大", "out": "缩小" }, - "imagery": { - "provided_by": "影像由{source}提供" - }, "gpx": { "local_layer": "本地GPX文件", "drag_drop": "把GPX文件拖到页面上。" @@ -2377,6 +2382,12 @@ locale.zh = { "office": { "name": "办公室" }, + "other": { + "name": "其他" + }, + "other_area": { + "name": "其他" + }, "place": { "name": "地点" }, @@ -2904,9 +2915,6 @@ locale.zh_TW = { "in": "放大", "out": "縮小" }, - "imagery": { - "provided_by": "影像由 {source} 提供" - }, "gpx": { "local_layer": "本機GPX檔案", "drag_drop": "拖放一個.gpx格式的檔案到本頁" @@ -4237,9 +4245,6 @@ locale.fr = { "in": "Zoomer", "out": "Dézoomer" }, - "imagery": { - "provided_by": "Image provenant de {source}" - }, "gpx": { "local_layer": "Fichier GPX personnel", "drag_drop": "Glisser et déposer un fichier .gpx sur la page" @@ -4774,6 +4779,7 @@ locale.de = { "reset": "Zurücksetzen" }, "restore": { + "heading": "Ungespeicherte Änderungen vorhanden", "description": "Es gibt ungespeicherte Änderungen aus einer vorherigen Sitzung. Möchtest du diese Änderungen wiederherstellen?", "restore": "Wiederherstellen", "reset": "Zurücksetzen" @@ -4792,6 +4798,7 @@ locale.de = { }, "source_switch": { "live": "live", + "lose_changes": "Es gibt ungespeicherte Änderungen. Durch Wechsel des Karten-Servers, gehen diese verloren. Sind Sie sicher, dass Sie die Server wechseln wollen?", "dev": "dev" }, "tag_reference": { @@ -4811,8 +4818,12 @@ locale.de = { "in": "Hineinzoomen", "out": "Herauszoomen" }, - "imagery": { - "provided_by": "Bilddaten von {source}" + "gpx": { + "local_layer": "Lokale GPX-Datei", + "drag_drop": "Eine GPX-Datei per Drag & Drop auf die Seite ziehen" + }, + "help": { + "title": "Hilfe" }, "presets": { "fields": { @@ -4831,12 +4842,24 @@ locale.de = { "aeroway": { "label": "Typ" }, + "amenity": { + "label": "Typ" + }, "atm": { "label": "Geldautomat" }, + "bicycle_parking": { + "label": "Typ" + }, "building": { "label": "Gebäude" }, + "building_area": { + "label": "Gebäude" + }, + "building_yes": { + "label": "Gebäude" + }, "capacity": { "label": "Kapazität" }, @@ -7010,9 +7033,6 @@ locale.pt = { "in": "Aproximar", "out": "Afastar" }, - "imagery": { - "provided_by": "Imagens disponibilizadas por {source}" - }, "gpx": { "local_layer": "Ficheiro GPX local", "drag_drop": "Arraste um ficheiro .gpx para a página" @@ -8502,9 +8522,6 @@ locale.uk = { "in": "Наблизитись", "out": "Віддалитись" }, - "imagery": { - "provided_by": "Фон наданий {source}" - }, "gpx": { "local_layer": "Локальний файл GPX", "drag_drop": "Перетягніть файл .gpx на сторінку" @@ -9603,7 +9620,7 @@ locale.vi = { "truncated_list": "Đang xem các đóng góp của {users} và {count} người khác" }, "geocoder": { - "title": "Tìm kiếm địa phương", + "title": "Tìm kiếm Địa phương", "placeholder": "Tìm kiếm địa phương", "no_results": "Không tìm thấy địa phương với tên “{name}”" }, @@ -9625,7 +9642,7 @@ locale.vi = { }, "background": { "title": "Hình nền", - "description": "Tùy chọn hình nền", + "description": "Tùy chọn Hình nền", "percent_brightness": "Sáng {opacity}%", "fix_misalignment": "Chỉnh lại hình nền bị chệch", "reset": "đặt lại" @@ -9646,7 +9663,9 @@ locale.vi = { }, "splash": { "welcome": "Chào mừng bạn đến với iD, chương trình sửa đổi OpenStreetMap", - "text": "Đây là phiên bản đang phát triển {version}. Xem thêm thông tin tại {website} và báo cáo lỗi tại {github}." + "text": "Đây là phiên bản đang phát triển {version}. Xem thêm thông tin tại {website} và báo cáo lỗi tại {github}.", + "walkthrough": "Mở trình hướng dẫn", + "start": "Tiến hành sửa đổi" }, "source_switch": { "live": "thật", @@ -9670,9 +9689,6 @@ locale.vi = { "in": "Phóng to", "out": "Thu nhỏ" }, - "imagery": { - "provided_by": "Hình ảnh do {source} cung cấp" - }, "gpx": { "local_layer": "Tập tin GPX địa phương", "drag_drop": "Kéo thả một tập tin .gpx vào trang" @@ -10368,6 +10384,12 @@ locale.vi = { "office": { "name": "Văn phòng" }, + "other": { + "name": "Khác" + }, + "other_area": { + "name": "Khác" + }, "place": { "name": "Địa phương" }, diff --git a/data/update_locales.js b/data/update_locales.js index 5bcccf70f..92b887ad0 100644 --- a/data/update_locales.js +++ b/data/update_locales.js @@ -61,16 +61,17 @@ function getResource(resource, callback) { function getLanguage(resource) { return function(code, callback) { - request.get(resource+ 'translation/' + code, { auth : auth }, function(err, resp, body) { + request.get(resource + 'translation/' + code, { auth : auth }, + function(err, resp, body) { if (err) return callback(err); callback(null, JSON.parse(body).content); }); }; } - function getLanguages(resource, callback) { - request.get(resource + '?details', { auth: auth }, function(err, resp, body) { + request.get(resource + '?details', { auth: auth }, + function(err, resp, body) { if (err) return callback(err); callback(null, JSON.parse(body).available_languages.map(function(d) { return d.code; diff --git a/index.html b/index.html index c682f017b..9efc5e3cc 100644 --- a/index.html +++ b/index.html @@ -31,6 +31,7 @@ + diff --git a/js/id/ui/help.js b/js/id/ui/help.js index e4b1ed1bc..b706f513f 100644 --- a/js/id/ui/help.js +++ b/js/id/ui/help.js @@ -24,8 +24,26 @@ iD.ui.Help = function(context) { }); } + var docKeys = [ + 'help.help', + 'help.editing_saving', + 'help.roads', + 'help.gps', + 'help.imagery', + 'help.addresses', + 'help.inspector', + 'help.buildings']; + + function one(f) { return function(x) { return f(x); }; } + var docs = docKeys.map(one(t)).map(function(text) { + return { + title: text.split('\n')[0].replace('#', '').trim(), + html: marked(text.split('\n').slice(1).join('\n')) + }; + }); + var menuItems = toc.selectAll('li') - .data(iD.data.doc) + .data(docs) .enter() .append('li') .append('a') @@ -47,7 +65,7 @@ iD.ui.Help = function(context) { body = content.append('div') .attr('class', 'body'); - clickHelp(iD.data.doc[0]); + clickHelp(docs[0]); } function hide() { setVisible(false); } diff --git a/js/lib/marked.js b/js/lib/marked.js new file mode 100644 index 000000000..b85ffa583 --- /dev/null +++ b/js/lib/marked.js @@ -0,0 +1,1127 @@ +/** + * marked - a markdown parser + * Copyright (c) 2011-2013, Christopher Jeffrey. (MIT Licensed) + * https://github.com/chjj/marked + */ + +;(function() { + +/** + * Block-Level Grammar + */ + +var block = { + newline: /^\n+/, + code: /^( {4}[^\n]+\n*)+/, + fences: noop, + hr: /^( *[-*_]){3,} *(?:\n+|$)/, + heading: /^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/, + nptable: noop, + lheading: /^([^\n]+)\n *(=|-){3,} *\n*/, + blockquote: /^( *>[^\n]+(\n[^\n]+)*\n*)+/, + list: /^( *)(bull) [\s\S]+?(?:hr|\n{2,}(?! )(?!\1bull )\n*|\s*$)/, + html: /^ *(?:comment|closed|closing) *(?:\n{2,}|\s*$)/, + def: /^ *\[([^\]]+)\]: *]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$)/, + table: noop, + paragraph: /^((?:[^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))+)\n*/, + text: /^[^\n]+/ +}; + +block.bullet = /(?:[*+-]|\d+\.)/; +block.item = /^( *)(bull) [^\n]*(?:\n(?!\1bull )[^\n]*)*/; +block.item = replace(block.item, 'gm') + (/bull/g, block.bullet) + (); + +block.list = replace(block.list) + (/bull/g, block.bullet) + ('hr', /\n+(?=(?: *[-*_]){3,} *(?:\n+|$))/) + (); + +block._tag = '(?!(?:' + + 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code' + + '|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo' + + '|span|br|wbr|ins|del|img)\\b)\\w+(?!:/|@)\\b'; + +block.html = replace(block.html) + ('comment', //) + ('closed', /<(tag)[\s\S]+?<\/\1>/) + ('closing', /])*?>/) + (/tag/g, block._tag) + (); + +block.paragraph = replace(block.paragraph) + ('hr', block.hr) + ('heading', block.heading) + ('lheading', block.lheading) + ('blockquote', block.blockquote) + ('tag', '<' + block._tag) + ('def', block.def) + (); + +/** + * Normal Block Grammar + */ + +block.normal = merge({}, block); + +/** + * GFM Block Grammar + */ + +block.gfm = merge({}, block.normal, { + fences: /^ *(`{3,}|~{3,}) *(\S+)? *\n([\s\S]+?)\s*\1 *(?:\n+|$)/, + paragraph: /^/ +}); + +block.gfm.paragraph = replace(block.paragraph) + ('(?!', '(?!' + block.gfm.fences.source.replace('\\1', '\\2') + '|') + (); + +/** + * GFM + Tables Block Grammar + */ + +block.tables = merge({}, block.gfm, { + nptable: /^ *(\S.*\|.*)\n *([-:]+ *\|[-| :]*)\n((?:.*\|.*(?:\n|$))*)\n*/, + table: /^ *\|(.+)\n *\|( *[-:]+[-| :]*)\n((?: *\|.*(?:\n|$))*)\n*/ +}); + +/** + * Block Lexer + */ + +function Lexer(options) { + this.tokens = []; + this.tokens.links = {}; + this.options = options || marked.defaults; + this.rules = block.normal; + + if (this.options.gfm) { + if (this.options.tables) { + this.rules = block.tables; + } else { + this.rules = block.gfm; + } + } +} + +/** + * Expose Block Rules + */ + +Lexer.rules = block; + +/** + * Static Lex Method + */ + +Lexer.lex = function(src, options) { + var lexer = new Lexer(options); + return lexer.lex(src); +}; + +/** + * Preprocessing + */ + +Lexer.prototype.lex = function(src) { + src = src + .replace(/\r\n|\r/g, '\n') + .replace(/\t/g, ' ') + .replace(/\u00a0/g, ' ') + .replace(/\u2424/g, '\n'); + + return this.token(src, true); +}; + +/** + * Lexing + */ + +Lexer.prototype.token = function(src, top) { + var src = src.replace(/^ +$/gm, '') + , next + , loose + , cap + , bull + , b + , item + , space + , i + , l; + + while (src) { + // newline + if (cap = this.rules.newline.exec(src)) { + src = src.substring(cap[0].length); + if (cap[0].length > 1) { + this.tokens.push({ + type: 'space' + }); + } + } + + // code + if (cap = this.rules.code.exec(src)) { + src = src.substring(cap[0].length); + cap = cap[0].replace(/^ {4}/gm, ''); + this.tokens.push({ + type: 'code', + text: !this.options.pedantic + ? cap.replace(/\n+$/, '') + : cap + }); + continue; + } + + // fences (gfm) + if (cap = this.rules.fences.exec(src)) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'code', + lang: cap[2], + text: cap[3] + }); + continue; + } + + // heading + if (cap = this.rules.heading.exec(src)) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'heading', + depth: cap[1].length, + text: cap[2] + }); + continue; + } + + // table no leading pipe (gfm) + if (top && (cap = this.rules.nptable.exec(src))) { + src = src.substring(cap[0].length); + + item = { + type: 'table', + header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */), + align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */), + cells: cap[3].replace(/\n$/, '').split('\n') + }; + + for (i = 0; i < item.align.length; i++) { + if (/^ *-+: *$/.test(item.align[i])) { + item.align[i] = 'right'; + } else if (/^ *:-+: *$/.test(item.align[i])) { + item.align[i] = 'center'; + } else if (/^ *:-+ *$/.test(item.align[i])) { + item.align[i] = 'left'; + } else { + item.align[i] = null; + } + } + + for (i = 0; i < item.cells.length; i++) { + item.cells[i] = item.cells[i].split(/ *\| */); + } + + this.tokens.push(item); + + continue; + } + + // lheading + if (cap = this.rules.lheading.exec(src)) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'heading', + depth: cap[2] === '=' ? 1 : 2, + text: cap[1] + }); + continue; + } + + // hr + if (cap = this.rules.hr.exec(src)) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'hr' + }); + continue; + } + + // blockquote + if (cap = this.rules.blockquote.exec(src)) { + src = src.substring(cap[0].length); + + this.tokens.push({ + type: 'blockquote_start' + }); + + cap = cap[0].replace(/^ *> ?/gm, ''); + + // Pass `top` to keep the current + // "toplevel" state. This is exactly + // how markdown.pl works. + this.token(cap, top); + + this.tokens.push({ + type: 'blockquote_end' + }); + + continue; + } + + // list + if (cap = this.rules.list.exec(src)) { + src = src.substring(cap[0].length); + bull = cap[2]; + + this.tokens.push({ + type: 'list_start', + ordered: bull.length > 1 + }); + + // Get each top-level item. + cap = cap[0].match(this.rules.item); + + next = false; + l = cap.length; + i = 0; + + for (; i < l; i++) { + item = cap[i]; + + // Remove the list item's bullet + // so it is seen as the next token. + space = item.length; + item = item.replace(/^ *([*+-]|\d+\.) +/, ''); + + // Outdent whatever the + // list item contains. Hacky. + if (~item.indexOf('\n ')) { + space -= item.length; + item = !this.options.pedantic + ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '') + : item.replace(/^ {1,4}/gm, ''); + } + + // Determine whether the next list item belongs here. + // Backpedal if it does not belong in this list. + if (this.options.smartLists && i !== l - 1) { + b = block.bullet.exec(cap[i+1])[0]; + if (bull !== b && !(bull.length > 1 && b.length > 1)) { + src = cap.slice(i + 1).join('\n') + src; + i = l - 1; + } + } + + // Determine whether item is loose or not. + // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/ + // for discount behavior. + loose = next || /\n\n(?!\s*$)/.test(item); + if (i !== l - 1) { + next = item[item.length-1] === '\n'; + if (!loose) loose = next; + } + + this.tokens.push({ + type: loose + ? 'loose_item_start' + : 'list_item_start' + }); + + // Recurse. + this.token(item, false); + + this.tokens.push({ + type: 'list_item_end' + }); + } + + this.tokens.push({ + type: 'list_end' + }); + + continue; + } + + // html + if (cap = this.rules.html.exec(src)) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: this.options.sanitize + ? 'paragraph' + : 'html', + pre: cap[1] === 'pre' || cap[1] === 'script', + text: cap[0] + }); + continue; + } + + // def + if (top && (cap = this.rules.def.exec(src))) { + src = src.substring(cap[0].length); + this.tokens.links[cap[1].toLowerCase()] = { + href: cap[2], + title: cap[3] + }; + continue; + } + + // table (gfm) + if (top && (cap = this.rules.table.exec(src))) { + src = src.substring(cap[0].length); + + item = { + type: 'table', + header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */), + align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */), + cells: cap[3].replace(/(?: *\| *)?\n$/, '').split('\n') + }; + + for (i = 0; i < item.align.length; i++) { + if (/^ *-+: *$/.test(item.align[i])) { + item.align[i] = 'right'; + } else if (/^ *:-+: *$/.test(item.align[i])) { + item.align[i] = 'center'; + } else if (/^ *:-+ *$/.test(item.align[i])) { + item.align[i] = 'left'; + } else { + item.align[i] = null; + } + } + + for (i = 0; i < item.cells.length; i++) { + item.cells[i] = item.cells[i] + .replace(/^ *\| *| *\| *$/g, '') + .split(/ *\| */); + } + + this.tokens.push(item); + + continue; + } + + // top-level paragraph + if (top && (cap = this.rules.paragraph.exec(src))) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'paragraph', + text: cap[1][cap[1].length-1] === '\n' + ? cap[1].slice(0, -1) + : cap[1] + }); + continue; + } + + // text + if (cap = this.rules.text.exec(src)) { + // Top-level should never reach here. + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'text', + text: cap[0] + }); + continue; + } + + if (src) { + throw new + Error('Infinite loop on byte: ' + src.charCodeAt(0)); + } + } + + return this.tokens; +}; + +/** + * Inline-Level Grammar + */ + +var inline = { + escape: /^\\([\\`*{}\[\]()#+\-.!_>])/, + autolink: /^<([^ >]+(@|:\/)[^ >]+)>/, + url: noop, + tag: /^|^<\/?\w+(?:"[^"]*"|'[^']*'|[^'">])*?>/, + link: /^!?\[(inside)\]\(href\)/, + reflink: /^!?\[(inside)\]\s*\[([^\]]*)\]/, + nolink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/, + strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/, + em: /^\b_((?:__|[\s\S])+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/, + code: /^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/, + br: /^ {2,}\n(?!\s*$)/, + del: noop, + text: /^[\s\S]+?(?=[\\?(?:\s+['"]([\s\S]*?)['"])?\s*/; + +inline.link = replace(inline.link) + ('inside', inline._inside) + ('href', inline._href) + (); + +inline.reflink = replace(inline.reflink) + ('inside', inline._inside) + (); + +/** + * Normal Inline Grammar + */ + +inline.normal = merge({}, inline); + +/** + * Pedantic Inline Grammar + */ + +inline.pedantic = merge({}, inline.normal, { + strong: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/, + em: /^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/ +}); + +/** + * GFM Inline Grammar + */ + +inline.gfm = merge({}, inline.normal, { + escape: replace(inline.escape)('])', '~|])')(), + url: /^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/, + del: /^~~(?=\S)([\s\S]*?\S)~~/, + text: replace(inline.text) + (']|', '~]|') + ('|', '|https?://|') + () +}); + +/** + * GFM + Line Breaks Inline Grammar + */ + +inline.breaks = merge({}, inline.gfm, { + br: replace(inline.br)('{2,}', '*')(), + text: replace(inline.gfm.text)('{2,}', '*')() +}); + +/** + * Inline Lexer & Compiler + */ + +function InlineLexer(links, options) { + this.options = options || marked.defaults; + this.links = links; + this.rules = inline.normal; + + if (!this.links) { + throw new + Error('Tokens array requires a `links` property.'); + } + + if (this.options.gfm) { + if (this.options.breaks) { + this.rules = inline.breaks; + } else { + this.rules = inline.gfm; + } + } else if (this.options.pedantic) { + this.rules = inline.pedantic; + } +} + +/** + * Expose Inline Rules + */ + +InlineLexer.rules = inline; + +/** + * Static Lexing/Compiling Method + */ + +InlineLexer.output = function(src, links, options) { + var inline = new InlineLexer(links, options); + return inline.output(src); +}; + +/** + * Lexing/Compiling + */ + +InlineLexer.prototype.output = function(src) { + var out = '' + , link + , text + , href + , cap; + + while (src) { + // escape + if (cap = this.rules.escape.exec(src)) { + src = src.substring(cap[0].length); + out += cap[1]; + continue; + } + + // autolink + if (cap = this.rules.autolink.exec(src)) { + src = src.substring(cap[0].length); + if (cap[2] === '@') { + text = cap[1][6] === ':' + ? this.mangle(cap[1].substring(7)) + : this.mangle(cap[1]); + href = this.mangle('mailto:') + text; + } else { + text = escape(cap[1]); + href = text; + } + out += '' + + text + + ''; + continue; + } + + // url (gfm) + if (cap = this.rules.url.exec(src)) { + src = src.substring(cap[0].length); + text = escape(cap[1]); + href = text; + out += '' + + text + + ''; + continue; + } + + // tag + if (cap = this.rules.tag.exec(src)) { + src = src.substring(cap[0].length); + out += this.options.sanitize + ? escape(cap[0]) + : cap[0]; + continue; + } + + // link + if (cap = this.rules.link.exec(src)) { + src = src.substring(cap[0].length); + out += this.outputLink(cap, { + href: cap[2], + title: cap[3] + }); + continue; + } + + // reflink, nolink + if ((cap = this.rules.reflink.exec(src)) + || (cap = this.rules.nolink.exec(src))) { + src = src.substring(cap[0].length); + link = (cap[2] || cap[1]).replace(/\s+/g, ' '); + link = this.links[link.toLowerCase()]; + if (!link || !link.href) { + out += cap[0][0]; + src = cap[0].substring(1) + src; + continue; + } + out += this.outputLink(cap, link); + continue; + } + + // strong + if (cap = this.rules.strong.exec(src)) { + src = src.substring(cap[0].length); + out += '' + + this.output(cap[2] || cap[1]) + + ''; + continue; + } + + // em + if (cap = this.rules.em.exec(src)) { + src = src.substring(cap[0].length); + out += '' + + this.output(cap[2] || cap[1]) + + ''; + continue; + } + + // code + if (cap = this.rules.code.exec(src)) { + src = src.substring(cap[0].length); + out += '' + + escape(cap[2], true) + + ''; + continue; + } + + // br + if (cap = this.rules.br.exec(src)) { + src = src.substring(cap[0].length); + out += '
'; + continue; + } + + // del (gfm) + if (cap = this.rules.del.exec(src)) { + src = src.substring(cap[0].length); + out += '' + + this.output(cap[1]) + + ''; + continue; + } + + // text + if (cap = this.rules.text.exec(src)) { + src = src.substring(cap[0].length); + out += escape(cap[0]); + continue; + } + + if (src) { + throw new + Error('Infinite loop on byte: ' + src.charCodeAt(0)); + } + } + + return out; +}; + +/** + * Compile Link + */ + +InlineLexer.prototype.outputLink = function(cap, link) { + if (cap[0][0] !== '!') { + return '' + + this.output(cap[1]) + + ''; + } else { + return ''
+      + escape(cap[1])
+      + ''; + } +}; + +/** + * Smartypants Transformations + */ + +InlineLexer.prototype.smartypants = function(text) { + if (!this.options.smartypants) return text; + return text + .replace(/--/g, '—') + .replace(/'([^']*)'/g, '‘$1’') + .replace(/"([^"]*)"/g, '“$1”') + .replace(/\.{3}/g, '…'); +}; + +/** + * Mangle Links + */ + +InlineLexer.prototype.mangle = function(text) { + var out = '' + , l = text.length + , i = 0 + , ch; + + for (; i < l; i++) { + ch = text.charCodeAt(i); + if (Math.random() > 0.5) { + ch = 'x' + ch.toString(16); + } + out += '&#' + ch + ';'; + } + + return out; +}; + +/** + * Parsing & Compiling + */ + +function Parser(options) { + this.tokens = []; + this.token = null; + this.options = options || marked.defaults; +} + +/** + * Static Parse Method + */ + +Parser.parse = function(src, options) { + var parser = new Parser(options); + return parser.parse(src); +}; + +/** + * Parse Loop + */ + +Parser.prototype.parse = function(src) { + this.inline = new InlineLexer(src.links, this.options); + this.tokens = src.reverse(); + + var out = ''; + while (this.next()) { + out += this.tok(); + } + + return out; +}; + +/** + * Next Token + */ + +Parser.prototype.next = function() { + return this.token = this.tokens.pop(); +}; + +/** + * Preview Next Token + */ + +Parser.prototype.peek = function() { + return this.tokens[this.tokens.length-1] || 0; +}; + +/** + * Parse Text Tokens + */ + +Parser.prototype.parseText = function() { + var body = this.token.text; + + while (this.peek().type === 'text') { + body += '\n' + this.next().text; + } + + return this.inline.output(body); +}; + +/** + * Parse Current Token + */ + +Parser.prototype.tok = function() { + switch (this.token.type) { + case 'space': { + return ''; + } + case 'hr': { + return '
\n'; + } + case 'heading': { + return '' + + this.inline.output(this.token.text) + + '\n'; + } + case 'code': { + if (this.options.highlight) { + var code = this.options.highlight(this.token.text, this.token.lang); + if (code != null && code !== this.token.text) { + this.token.escaped = true; + this.token.text = code; + } + } + + if (!this.token.escaped) { + this.token.text = escape(this.token.text, true); + } + + return '
'
+        + this.token.text
+        + '
\n'; + } + case 'table': { + var body = '' + , heading + , i + , row + , cell + , j; + + // header + body += '\n\n'; + for (i = 0; i < this.token.header.length; i++) { + heading = this.inline.output(this.token.header[i]); + body += this.token.align[i] + ? '' + heading + '\n' + : '' + heading + '\n'; + } + body += '\n\n'; + + // body + body += '\n' + for (i = 0; i < this.token.cells.length; i++) { + row = this.token.cells[i]; + body += '\n'; + for (j = 0; j < row.length; j++) { + cell = this.inline.output(row[j]); + body += this.token.align[j] + ? '' + cell + '\n' + : '' + cell + '\n'; + } + body += '\n'; + } + body += '\n'; + + return '\n' + + body + + '
\n'; + } + case 'blockquote_start': { + var body = ''; + + while (this.next().type !== 'blockquote_end') { + body += this.tok(); + } + + return '
\n' + + body + + '
\n'; + } + case 'list_start': { + var type = this.token.ordered ? 'ol' : 'ul' + , body = ''; + + while (this.next().type !== 'list_end') { + body += this.tok(); + } + + return '<' + + type + + '>\n' + + body + + '\n'; + } + case 'list_item_start': { + var body = ''; + + while (this.next().type !== 'list_item_end') { + body += this.token.type === 'text' + ? this.parseText() + : this.tok(); + } + + return '
  • ' + + body + + '
  • \n'; + } + case 'loose_item_start': { + var body = ''; + + while (this.next().type !== 'list_item_end') { + body += this.tok(); + } + + return '
  • ' + + body + + '
  • \n'; + } + case 'html': { + return !this.token.pre && !this.options.pedantic + ? this.inline.output(this.token.text) + : this.token.text; + } + case 'paragraph': { + return '

    ' + + this.inline.output(this.token.text) + + '

    \n'; + } + case 'text': { + return '

    ' + + this.parseText() + + '

    \n'; + } + } +}; + +/** + * Helpers + */ + +function escape(html, encode) { + return html + .replace(!encode ? /&(?!#?\w+;)/g : /&/g, '&') + .replace(//g, '>') + .replace(/"/g, '"') + .replace(/'/g, '''); +} + +function replace(regex, opt) { + regex = regex.source; + opt = opt || ''; + return function self(name, val) { + if (!name) return new RegExp(regex, opt); + val = val.source || val; + val = val.replace(/(^|[^\[])\^/g, '$1'); + regex = regex.replace(name, val); + return self; + }; +} + +function noop() {} +noop.exec = noop; + +function merge(obj) { + var i = 1 + , target + , key; + + for (; i < arguments.length; i++) { + target = arguments[i]; + for (key in target) { + if (Object.prototype.hasOwnProperty.call(target, key)) { + obj[key] = target[key]; + } + } + } + + return obj; +} + +/** + * Marked + */ + +function marked(src, opt, callback) { + if (callback || typeof opt === 'function') { + if (!callback) { + callback = opt; + opt = null; + } + + if (opt) opt = merge({}, marked.defaults, opt); + + var tokens = Lexer.lex(tokens, opt) + , highlight = opt.highlight + , pending = 0 + , l = tokens.length + , i = 0; + + if (!highlight || highlight.length < 3) { + return callback(null, Parser.parse(tokens, opt)); + } + + var done = function() { + delete opt.highlight; + var out = Parser.parse(tokens, opt); + opt.highlight = highlight; + return callback(null, out); + }; + + for (; i < l; i++) { + (function(token) { + if (token.type !== 'code') return; + pending++; + return highlight(token.text, token.lang, function(err, code) { + if (code == null || code === token.text) { + return --pending || done(); + } + token.text = code; + token.escaped = true; + --pending || done(); + }); + })(tokens[i]); + } + + return; + } + try { + if (opt) opt = merge({}, marked.defaults, opt); + return Parser.parse(Lexer.lex(src, opt), opt); + } catch (e) { + e.message += '\nPlease report this to https://github.com/chjj/marked.'; + if ((opt || marked.defaults).silent) { + return '

    An error occured:

    '
    +        + escape(e.message + '', true)
    +        + '
    '; + } + throw e; + } +} + +/** + * Options + */ + +marked.options = +marked.setOptions = function(opt) { + merge(marked.defaults, opt); + return marked; +}; + +marked.defaults = { + gfm: true, + tables: true, + breaks: false, + pedantic: false, + sanitize: false, + smartLists: false, + silent: false, + highlight: null, + langPrefix: 'lang-' +}; + +/** + * Expose + */ + +marked.Parser = Parser; +marked.parser = Parser.parse; + +marked.Lexer = Lexer; +marked.lexer = Lexer.lex; + +marked.InlineLexer = InlineLexer; +marked.inlineLexer = InlineLexer.output; + +marked.parse = marked; + +if (typeof exports === 'object') { + module.exports = marked; +} else if (typeof define === 'function' && define.amd) { + define(function() { return marked; }); +} else { + this.marked = marked; +} + +}).call(function() { + return this || (typeof window !== 'undefined' ? window : global); +}()); diff --git a/js/lib/togeojson.js b/js/lib/togeojson.js index 65cfdd60f..74f741c88 100644 --- a/js/lib/togeojson.js +++ b/js/lib/togeojson.js @@ -22,7 +22,7 @@ toGeoJSON = (function() { return o; } function fc() { return { type: 'FeatureCollection', features: [] }; } - t = { + var t = { kml: function(doc, o) { o = o || {}; var gj = fc(), styleIndex = {}, diff --git a/package.json b/package.json index 6d8d7ba81..4cd2317a8 100644 --- a/package.json +++ b/package.json @@ -29,8 +29,5 @@ }, "engines": { "node": "~0.8.20" - }, - "dependencies": { - "marked": "~0.2.8" } } diff --git a/test/spec/presets/preset.js b/test/spec/presets/preset.js index 6f1305966..6e8015c9c 100644 --- a/test/spec/presets/preset.js +++ b/test/spec/presets/preset.js @@ -73,8 +73,6 @@ describe('iD.presets.Preset', function() { describe('#applyTags', function() { it("adds match tags", function() { - console.log(p['highway/residential']); - console.log(p['highway/residential'].applyTags({}, 'area')); expect(p['highway/residential'].applyTags({}, 'area')).to.eql({ highway: 'residential' }); });