Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用PHP-FineDiff,显示学生输出和标准答案的diff状态 #39

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions details.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,48 @@ function format_stderr($string) {
return format_compileroutput($string);
}

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style type="text/css">
ins {color:green;background:#dfd;text-decoration:none}
del {color:red;background:#fdd;text-decoration:none}
.pane {margin:0;padding:0;border:0;width:100%;min-height:30em;overflow:auto;font:12px monospace}
.diff {color:gray}
</style>
</head>
<body>
<div>
<?php
include 'finediff.php';

$granularity = 3;

$from_text = $task[0];
$to_text = $task[1];
$diff = '';
$granularityStacks = array(
FineDiff::$paragraphGranularity,
FineDiff::$sentenceGranularity,
FineDiff::$wordGranularity,
FineDiff::$characterGranularity
);

$from_len = strlen($from_text);
$to_len = strlen($to_text);
$diff = new FineDiff($from_text, $to_text, FineDiff::$characterGranularity);
$edits = $diff->getOps();
$rendered_diff = $diff->renderDiffToHTML();
$diff_len = strlen($diff->getOpcodes());
?>
<div class="pane diff" style="white-space:pre-line">
(diff len: <?php echo $diff_len; ?> chars)
<?php echo $rendered_diff; ?>
</div>
</div>
</body>
</html>

<?php
Loading