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:
Nasser Grainawi
2012-05-08 18:56:39 -07:00
parent e033b2620d
commit bf4fa34606
5 changed files with 101 additions and 5 deletions

View File

@@ -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
}