Auto-format plugin HTTP pages from known formats
If we detect the requested plugin resource does not exist, but a file with a .md extension instead does exist, open the .md file and reformat as html. Do that reformatting using the pegdown library. Change-Id: I29e1b1c58607a9faf2acfdc387a7418b545c5b48
This commit is contained in:
		| @@ -0,0 +1,35 @@ | ||||
| // Copyright (C) 2012 The Android Open Source Project | ||||
| // | ||||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| // you may not use this file except in compliance with the License. | ||||
| // You may obtain a copy of the License at | ||||
| // | ||||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||||
| // | ||||
| // Unless required by applicable law or agreed to in writing, software | ||||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | ||||
|  | ||||
| package com.google.gerrit.server.documentation; | ||||
|  | ||||
| import static org.pegdown.Extensions.ALL; | ||||
|  | ||||
| import org.eclipse.jgit.util.RawParseUtils; | ||||
| import org.pegdown.PegDownProcessor; | ||||
|  | ||||
| import java.io.UnsupportedEncodingException; | ||||
| import java.nio.charset.Charset; | ||||
|  | ||||
| public class MarkdownFormatter { | ||||
|  | ||||
|   public byte[] getHtmlFromMarkdown(byte[] data, String charEnc) | ||||
|       throws UnsupportedEncodingException { | ||||
|     String decodedData = RawParseUtils.decode(Charset.forName(charEnc), data); | ||||
|     String formatted = new PegDownProcessor(ALL).markdownToHtml(decodedData); | ||||
|     data = formatted.getBytes(charEnc); | ||||
|     return data; | ||||
|   } | ||||
|   // TODO: Add a cache | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Nasser Grainawi
					Nasser Grainawi