blob: c065cb1e9b0b26dfb1091061f61e017c60d0c183 [file] [log] [blame]
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:convert';
import 'package:dartdoc/src/model/annotation.dart';
import 'package:dartdoc/src/model/attribute.dart';
const _htmlEscape = HtmlEscape();
/// A renderer for subclasses of [Attribute].
///
/// (The base class does not require separate rendering, represented by
/// pre-defined constant strings.)
abstract class AttributeRenderer {
const AttributeRenderer();
/// Render this [Annotation].
String renderAnnotation(Annotation attribute);
}
/// A HTML renderer for an [Attribute].
class AttributeRendererHtml extends AttributeRenderer {
const AttributeRendererHtml();
@override
String renderAnnotation(Annotation attribute) =>
'@${attribute.linkedName}${_htmlEscape.convert(attribute.parameterText)}';
}
/// A Markdown renderer for an [Attribute].
class AttributeRendererMd extends AttributeRenderer {
const AttributeRendererMd();
@override
String renderAnnotation(Annotation attribute) =>
'@${attribute.linkedName}${_htmlEscape.convert(attribute.parameterText)}';
}