|
| 1 | +/* |
| 2 | + * SPDX-License-Identifier: Apache-2.0 |
| 3 | + * |
| 4 | + * Copyright 2024 The Enola <https://enola.dev> Authors |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | +package dev.enola.common.io.mediatype; |
| 19 | + |
| 20 | +import static com.google.common.net.MediaType.create; |
| 21 | + |
| 22 | +import com.google.common.base.Charsets; |
| 23 | +import com.google.common.collect.ImmutableMap; |
| 24 | +import com.google.common.collect.ImmutableSet; |
| 25 | +import com.google.common.net.MediaType; |
| 26 | + |
| 27 | +import java.util.Map; |
| 28 | +import java.util.Set; |
| 29 | + |
| 30 | +/** |
| 31 | + * The "text/markdown" media type, as per <a href="https://www.rfc-editor.org/rfc/rfc7763.html">RFC |
| 32 | + * 7763</a> (and <a href="https://www.rfc-editor.org/rfc/rfc7764.html">RFC 7764</a>). |
| 33 | + */ |
| 34 | +public class MarkdownMediaTypes implements MediaTypeProvider { |
| 35 | + |
| 36 | + // TODO Distinguish https://commonmark.org from GFH et al. via a variant parameter; see |
| 37 | + // https://www.iana.org/assignments/markdown-variants/markdown-variants.xhtml |
| 38 | + |
| 39 | + public static final MediaType MARKDOWN_UTF_8 = |
| 40 | + create("text", "markdown").withCharset(Charsets.UTF_8); |
| 41 | + ; |
| 42 | + |
| 43 | + @Override |
| 44 | + public Map<String, MediaType> extensionsToTypes() { |
| 45 | + return ImmutableMap.of("md", MARKDOWN_UTF_8); |
| 46 | + } |
| 47 | + |
| 48 | + @Override |
| 49 | + public Map<MediaType, Set<MediaType>> knownTypesWithAlternatives() { |
| 50 | + return ImmutableMap.of(MARKDOWN_UTF_8, ImmutableSet.of(create("text", "x-markdown"))); |
| 51 | + } |
| 52 | +} |
0 commit comments