diff options
author | cduvall@chromium.org <cduvall@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-26 02:58:13 +0000 |
---|---|---|
committer | cduvall@chromium.org <cduvall@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-26 02:58:13 +0000 |
commit | 04f84384d10225474c86158dd960a6451d278dd1 (patch) | |
tree | 263abe5113e8c0321bf7aa3faf6c48f5be03fb5f | |
parent | 7b24a4db4afbd3fd8b3b7792a4af277f786d84ec (diff) | |
download | chromium_src-04f84384d10225474c86158dd960a6451d278dd1.zip chromium_src-04f84384d10225474c86158dd960a6451d278dd1.tar.gz chromium_src-04f84384d10225474c86158dd960a6451d278dd1.tar.bz2 |
Extensions Docs Server: Add <br/>s to multi line IDL comments
Some IDL comments that spanned multiple lines looked weird because all the text
ran together. For an example see:
http://developer.chrome.com/trunk/apps/app.window.html#method-create
This also fixes doubly-escaped quotes in the IDL files.
BUG=149143, 146977
Review URL: https://chromiumcodereview.appspot.com/10986018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@158732 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | tools/json_schema_compiler/idl_schema.py | 16 | ||||
-rwxr-xr-x | tools/json_schema_compiler/idl_schema_test.py | 6 | ||||
-rw-r--r-- | tools/json_schema_compiler/schema_bundle_generator.py | 5 | ||||
-rw-r--r-- | tools/json_schema_compiler/test/idl_basics.idl | 2 |
4 files changed, 17 insertions, 12 deletions
diff --git a/tools/json_schema_compiler/idl_schema.py b/tools/json_schema_compiler/idl_schema.py index 6693ed4..1785b34 100644 --- a/tools/json_schema_compiler/idl_schema.py +++ b/tools/json_schema_compiler/idl_schema.py @@ -56,10 +56,6 @@ def ProcessComment(comment): } ) ''' - - # Escape double quotes. - comment = comment.replace('"', '\\"'); - # Find all the parameter comments of the form '|name|: comment'. parameter_starts = list(re.finditer(r'\n *\|([^|]*)\| *: *', comment)) @@ -67,7 +63,12 @@ def ProcessComment(comment): first_parameter_location = (parameter_starts[0].start() if parameter_starts else len(comment)) parent_comment = comment[:first_parameter_location] - parent_comment = parent_comment.replace('\n', '').strip() + + # We replace \n\n with <br/><br/> here and below, because the documentation + # needs to know where the newlines should be, and this is easier than + # escaping \n. + parent_comment = (parent_comment.strip().replace('\n\n', '<br/><br/>') + .replace('\n', '')) params = {} for (cur_param, next_param) in itertools.izip_longest(parameter_starts, @@ -78,8 +79,9 @@ def ProcessComment(comment): # beginning of the next parameter's introduction. param_comment_start = cur_param.end() param_comment_end = next_param.start() if next_param else len(comment) - params[param_name] = comment[param_comment_start:param_comment_end - ].replace('\n', '').strip() + params[param_name] = (comment[param_comment_start:param_comment_end + ].strip().replace('\n\n', '<br/><br/>') + .replace('\n', '')) return (parent_comment, params) class Callspec(object): diff --git a/tools/json_schema_compiler/idl_schema_test.py b/tools/json_schema_compiler/idl_schema_test.py index 8a050f9..bca451b 100755 --- a/tools/json_schema_compiler/idl_schema_test.py +++ b/tools/json_schema_compiler/idl_schema_test.py @@ -59,7 +59,7 @@ class IdlSchemaTest(unittest.TestCase): def testLegalValues(self): self.assertEquals({ 'x': {'name': 'x', 'type': 'integer', 'enum': [1,2], - 'description': 'This comment tests \\\"double-quotes\\\".'}, + 'description': 'This comment tests "double-quotes".'}, 'y': {'name': 'y', 'type': 'string'}}, getType(self.idl_basics, 'idl_basics.MyType1')['properties']) @@ -103,8 +103,8 @@ class IdlSchemaTest(unittest.TestCase): '$ref': 'idl_basics.MyType1'}], func['parameters']) func = getFunction(schema, 'function4') - self.assertEquals(('This tests if \\\"double-quotes\\\" are escaped ' - 'correctly.'), + self.assertEquals(('This tests if "double-quotes" are escaped correctly.' + '<br/><br/> It also tests a comment with two newlines.'), func['description']) if __name__ == '__main__': diff --git a/tools/json_schema_compiler/schema_bundle_generator.py b/tools/json_schema_compiler/schema_bundle_generator.py index 41dd734..d391ea7 100644 --- a/tools/json_schema_compiler/schema_bundle_generator.py +++ b/tools/json_schema_compiler/schema_bundle_generator.py @@ -127,8 +127,9 @@ class SchemaBundleGenerator(object): namespace = self._model.namespaces[api.get('namespace')] # JSON parsing code expects lists of schemas, so dump a singleton list. json_content = json.dumps([api], indent=2) - # Escape all double-quotes. Ignore already-escaped double-quotes. - json_content = re.sub('(?<!\\\\)"', '\\"', json_content) + # Escape all double-quotes and backslashes. For this to output a valid + # JSON C string, we need to escape \ and ". + json_content = json_content.replace('\\', '\\\\').replace('"', '\\"') lines = json_content.split('\n') c.Append('(*schemas)["%s"] = ' % namespace.name) for index, line in enumerate(lines): diff --git a/tools/json_schema_compiler/test/idl_basics.idl b/tools/json_schema_compiler/test/idl_basics.idl index 561bd38..eb4ec62 100644 --- a/tools/json_schema_compiler/test/idl_basics.idl +++ b/tools/json_schema_compiler/test/idl_basics.idl @@ -39,6 +39,8 @@ static void function3(MyType1 arg); // This tests if "double-quotes" are escaped correctly. + // + // It also tests a comment with two newlines. static void function4(Callback1 cb); static void function5(Callback2 cb); static void function6(Callback3 cb); |